Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DBGrid - Multiple row select like Excel

Status
Not open for further replies.

TerP1

Programmer
Jul 14, 2003
8
GB
I have a custom DBGrid I have wrote that allows the user to select multiple rows by dragging the mouse over the data like in Excel. However if I drag the mouse too fast it misses rows and I have gaps in my selections. It works on mouse down and mouse move events. The trouble is the mouse move event doesn't seem to be firing often enough hence the gaps.

Can anyone help in any way? Are there better ways to achieve this and is there a more suitable event I can use?

Thanks

T
 
I guess most of us will find it difficult to help unless you show us the code of your component. In particular the event handlers relating to the row selection.

Andrew
 
Thanks for the link. I can select multiple records using ctrl or shift and the mouse but I want to be able to drag the mouse up and down the grid and have those records selected and deselected dynamically like Excel.

OK the mouse down event. Selects the current record

case MouseMode of
mTopLeft, mTitle:
Invalidate;
mIndicator:
if Button = mbLeft then
begin
BeginUpdate;
tryFDatalink.UpdateData;
FDatalink.MoveBy(MouseDownCell.Y - Row);
IndicatorSelecting := NOT fBookmarks.IsSelected(fRecNo);
FBookmarks.SelectRecord(fRecNo, IndicatorSelecting)
finally
EndUpdate;
Invalidate
end
end;




The mouse move event

case MouseMode of

mIndicator:
//if current X,Y is different to initial mouse down X,Y or exceeds screen dimensions
if (Cell.X <> MouseDownCell.X) OR (Cell.Y <> MouseDownCell.Y) OR (Y > ClientHeight) OR (Y < 0) then
begin
if Cell.Y >= FTitleOffset then

MouseDownCell := Cell;
FBookmarks.SelectRecord (fRecNo,IndicatorSelecting); //selects the record



There is some more code to this but not really related to this. This is the core actions behind the selection of rows.

Thanks for any help.

T
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top