Select DBGrid Row and StringGrid recognize line NUMBER

1

Would you be able to tell me if there is a possibility when I select a line from DBGrid , my StringGrid just recognize which line I selected?

I'm not doing functions: I'm just doing this kind of thing for information for the user, that is, my DBGrid has 2000 records found , and my StringGrid also, however, DBGrid has the database records, and StringGrid of another file. All I need is that at the time I select the record, on the line the StringGrid recognizes which line I selected and go to it, without needing to search.

To be clearer, I want some event, according to system execution, when I select a particular line of DBGrid , StringGrid recognize and go to the respective line of DBGrid .

How to do it?

    
asked by anonymous 19.05.2014 / 20:49

1 answer

3

First set the following option in your DBGrid:

dgrowselect := True;

Then,itsDBGridhasaDataSourceanditisboundtoaDataSet(beitaQuery,ClientDataset,whatever).Ithasanindex.

In the case below the index is dbgOFD.DataSource.DataSet.RecNo

With this index you change the following code snippet:

StringGrid1.Col :=0;
StringGrid1.Row :=1; //dbgOFD.DataSource.DataSet.RecNo - 1
StringGrid1.Selection:=TGridRect(Rect(0,1 ,MaxInt ,1));
StringGrid1.SetFocus;

Note: Note that StringGrid must have at least the same number of lines as DBGrid . If you do not, you'll have to handle the exception.

    
20.05.2014 / 14:27