November 30th, 2013, 10:55 AM
How to get focused or selcted row data from DBGrid/ DBAdvGrid
How to get focused or selected row data from DBGrid or DBAdvGrid as shown in figure below ?
Is there any method at DBGrid/ DBAdvGrid which enables us to get selected data or do we have to use Dataset associated with DBGrid/DBAdvGrid
I already tried to use
In above figure it is expected to return 3rd row result but it is returning first row result with this method
edtLabel.Text := DBAdvGrid1.DataSource.DataSet.FieldByName('label').Value;
This method is returning error.
edtLabel.Text := MainFrm.FrmMain.DBAdvGrid1.Fields.Value;
Is there any way to extract data from focused row as shown in above figure (Focused row no 3) ?
November 30th, 2013, 09:58 PM
Your first attempt should work, I would change .Value to .AsString. Perhaps you attached your code to the wrong event (such as OnCreate - When the first record in selected). Attach the code to your Query's AfterScroll event.
edtLabel.Text := DBAdvGrid1.DataSource.DataSet.FieldByName('label').AsString;
Comments on this post
December 1st, 2013, 07:44 AM
Yes it is working perfectly with Querys AfterScroll event.