Select Dbgrid Line and Stringgrid recognize the line NUMBER

Asked

Viewed 7,056 times

1

Would you know to tell me if there’s a possibility when I select a line from the DBGrid, my StringGrid just recognize which line I selected?

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

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

How to do?

  • You spoke of StringList and StringGrid. Which one is right, after all? And what fills them? There is a relationship between a record shown in DBGrid and a row of this other grid or list?

  • So @Alexsc, I said StringList first, but I was wrong, as I edited up there, now it’s StringGrid. It would help?

  • You want me to, when I select the 1000 line of the DBGrid, the line 1000 of TStringGrid is selected or when selecting a line from DBGrid the system looks for a "pair" in the TStringGrid? Edit your question to make it clearer please

  • Could you show a little code? Just a small example of what you need, probably inside the event click.

  • @Filipe.Fonseca, exactly this, I edited my question.

  • 1

    Exactly what? I gave two chances, 1 or 2? :)

  • @Math, I don’t mean a code, because I can’t think of any, I don’t know the structure of Dbgrid, as for Stringgrid, I’m sure it’s related to the code : StringGrid1.Row, I tried to match the Dbgrid Rows, but I don’t know the option.

  • @Filipe.Fonseca EHAUEHAUHEAUHEAUHE, Sorry man, it’s a rush I just read the first one. So it’s the first msm.

Show 3 more comments

1 answer

3


First set the following option in your Dbgrid:

dgrowselect := True;

dgrowselect

Then his DBGrid has a DataSource and this is linked to a Dataset (be this one Query, ClientDataset, whatever). This has an index.

inserir a descrição da imagem aqui

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 the StringGrid must have at least the same amount of lines DBGrid. If not, you will have to treat the exception.

  • can I put the code in Formactivate? or have a specific event to put the code?

  • I think the ideal would be OnColEnter or in the OnCellClick of DBGrid.

  • beauty, I’m going to test now msm, another question, in the case of the dataset, I would use the code commented right?

  • 1

    Exactly. A variable of it, depending on the type of dataset.

  • I am using a Query even, I will use this code msm that is pointing above, for now it is not selecting anything because my query is giving problem in relation to date input (Conversation) T.T

  • Thanks man! It was right!

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.