Board index » delphi » Sequence of mouse and keyboard events when selecting cells in a drawgrid
Chris Hill
![]() Delphi Developer |
Sat, 01 Jan 2005 22:05:53 GMT
Sequence of mouse and keyboard events when selecting cells in a drawgridI am developing an application which uses a DrawGrid to present the user with rows of data to be selected. The data is order lines ready for despatch, and is grouped under customer and ship to location headings. I am using a Drawgrid with an oncelldraw event to create the data, with different highlighting for the different row types, and pulling the data from several lists of objects downloaded from our AS/400. I need the user to be able to select multiple rows, within a shipto. These can be contiguous or non-contiguous. So far, I have got it working with the cursor, page up/down, and home/end keys, in combination with shift and ctrl, to enable the user to navigate the grid, moving from shipto to shipto with page up/down, and selecting either single rows, complete shiptos or contiguous rows. I maintain my own array of selected rows and use the onkeydown event to save the key press data and the onselectcell event to carry out the actions depending on the key that was pressed. In processing the key in the onselectcell event, I set the selected row into the Row property of the grid, which also fires onselectcell, and also reposition the TopRow is needed. I now want to add mouse selection, to enable the user to select single, contiguous and discontiguous rows, as in Explorer with single click, plus shift or ctrl. However, the events fire in a different order, which also depend on which key is pressed, and the onselectcell fires before the mousedown event, so I cannot identify which buttons the user pressed in the onselectcell event. I also need to distinguish between single click - to select; double click - to carry out an action, like ENTER; and rightclick - to display a popup menu. I suspect that part of the answer lies in the onselectcell event always assuming that it need do nothing, unless the immediately preceding event was a keydown. This means it will ignore mouse clicks and any nested evocations from itself changing the Row property. I should then be able to handle the mouse events in onmousedown, onclick and ondoubleclick events. Right click should be easy - it just fires mousedown, so i can check the the right button. However, single and double click are harder to distinguish. The sequence of events I get seems to be : Left Click Left Double Click Right Click How can I identify a single click, other than by the absence of the doubleclick. Also, cursor selection also fires the singleclick event. regards Chris |