BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

TDBGrid and Multiselection

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (ADO)
View previous topic :: View next topic  
Author Message
Gunnar Liknes
Guest





PostPosted: Tue Aug 10, 2004 3:43 pm    Post subject: TDBGrid and Multiselection Reply with quote



Hi,

I have searched allover the place but cannot find a simple solution to this
simple
problem:

I have a TDBGrid which displayes the result of a query. I have enabled
multiselect and rowselect.

Problem:

When the user changes the selection I need to update a label with
information
about the selection. For now I just set the labels caption to the number of
rows
selected.

Howeever I cannot find any event that triggers when the selection change. I
have
found a few which trigger when the active record change (i.e.
Dataset.Afterscroll,
dataset.omMoveComplete and datasource on dataChange), however it seems like
theese events fire before the new row is added to the selection as
Selectedrows.count
is always 1 less than it should be if I update the label inside one of them.

I have tried to put the following code inside almost any data/row change
event in
the object inspector:

Label26.Caption:=intToStr(DBGrid1.SelectedRows.Count);

DBGrid1.SelectedRows.Count is always 1 less than the actual rows selected.

If I add the same line in a Tbutton's onclick event the SelectedRows.Count
value is correct;

Is there any solution to this?

Cheers
Gunnar


Back to top
Gunnar Liknes
Guest





PostPosted: Tue Aug 10, 2004 4:17 pm    Post subject: Re: TDBGrid and Multiselection Reply with quote



"Gunnar Liknes" wrote

Quote:
I have a TDBGrid which displayes the result of a query. I have enabled
multiselect and rowselect.

Problem:

When the user changes the selection I need to update a label with
information
about the selection. For now I just set the labels caption to the number
of
rows
selected.

Howeever I cannot find any event that triggers when the selection change.
I
have
found a few which trigger when the active record change (i.e.
Dataset.Afterscroll,
dataset.omMoveComplete and datasource on dataChange), however it seems
like
theese events fire before the new row is added to the selection as
Selectedrows.count
is always 1 less than it should be if I update the label inside one of
them.


I found a solution myself:

If I send a message to myself in the DataSource.DataChange event like this:

PostMessage(Self.Handle, UM_SelectionChange, 0,0);

Then RowsSelected.count is updated by the time I get the message, and I
can do my stuff in the messagehandler Smile.

Regards
Gunnar



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (ADO) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.