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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DBGrid Selected Rows in order selected 2

Status
Not open for further replies.

StevenK

Programmer
Jan 5, 2001
1,294
0
0
GB
I may be trying to achieve too much with this one.
I'm able to set a DBGrid to allow multiple rows to be selected and then step through those that are selected and output the entries to a listbox (for instance). However these selected rows are listed in a top-down fashion as seen in the grid as rather than the order in which they were selected, ie. selecting row 10, then row 3, then row 7 will return the list selected 3, 7, 10.
Is there any fail-safe (idiot-proof) way of obtaining the list of entries in the order in which they were selected ?
Thanks for any help in advance.
Steve
 
Hi StevenK,
I don't know if this will help because normally you are the one that solve my problems ;-)

Well, it is not an ellegant solution but it solves the problem I think.

Var
Ordered_Selection:TList;
Ordered_Item=record
Id: ????
//this would point to the item in the grid
(...)
end;

// I would use the MouseDown event to catch the
// beggining of the multiselect.

Procedure TDbGrid.MouseDown(Sender:TObject);
Begin

If Key_Pressed(vkControl) Then
Ordered_Selection.Add(New_Ordered_Item)
Else
Begin
Ordered_Selection.Delete_All;
Ordered_Selection.Add(New_Ordered_Item);
End;
End;

// New_Order_Item could be a funtion that gets the info
// from the active row...
// When you need to acces to the selected items do it
// through Ordered_Selection (of course)

Well, this seems stupid, it is?

Hope this helps,
Dani.
 
You need to look at qrySource.SetBookmark, qrySource.GetBookmark.

With the OnCellClick, do your SetBookmark.

When selection is complete, step through the bookmark list - this should go thru' the dataset in the selection order

lou
[penguin]
 
Thanks. The ideas suggested make sense - I'm now having problems filling in the gaps.
1. On the CellClick event I need to check if the 'Ctrl' is still held down. How do I do this ? If the 'Ctrl' key is no longer held down then I need to start the list afresh
2. How safe a method is this making use of TBookMarks ? Someone previously suggest that they shouldn't be relied upon ??
Thanks again.
Steve
 
Steve

If you post your email, I can send you some working code.

Personally, I've never had problems with Bookmarks, but I suppose there's time...

lou
 
Thanks again.
Steve

(e-mail : steven.keclik@s3t.co.uk)
 
I'm still struggling with this problem.
I've been going along the suggestion of creating a list of TBookMarks as I select each record and then cycling through these in the order the entries were selected.
Simplifying the problem to trying to capture the use of 'Ctrl' and 'Left' mouse button clicks I've tried a simple 'out of application' test program.
I've been using the method of utilising the DBGrid's 'OnMouseDown' event. If I have an empty DBGrid and use the code :
procedure TForm1.DBGrid1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if (Button = mbLeft) then
begin
ShowMessage('Left Button');
if (ssCtrl in Shift) then
begin
ShowMessage('Ctrl held down');
end;
end;
end;

When I have no DataSource set for the DBGrid this runs OK, presenting the message 'Left Button' if the left mouse button is clicked and then 'Ctrl held down' if the 'Ctrl' key is held down (as well as Left button being clicked).
If I set the DataSource property of the DBGrid then I suddenly lose the messages that should be shown.
I'm guessing the DBGrid is over-riding my code.
Can anyone suggest a way around this ?
Thanks in advance.
Steve
 
hi Steve

Try putting the code in the MouseUp event. I got it working ok in this event.

lou
 
Thanks for the pointer.
It now works as I want it to.
Much appreciated.
Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top