Link to home
Start Free TrialLog in
Avatar of cypherbad
cypherbad

asked on

Get selected line in dbgrid

Hi experts,
I work with dbgrids and i need to get the value of the first row on the selected line. How can i do this?

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of rfwoolf
rfwoolf
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cypherbad
cypherbad

ASKER

thanks for the quick answer, i'll test it right away!
There is also a way to refer to the first column by number instead of by name, try something like this:
  MyDataset.Fields[0].AsString;

Here's another trick. You can refer to your dataset indirectly by going through the DBGrid:

DBGrid1.Datasource.Dataset.Fields[0].AsString;

Note the 'AsString' part - you have other options like .value, .AsInteger, .AsFloat, .AsCurrency, .AsBoolean etc
Please open this: http://i32.tinypic.com/2wbzuqu.jpg
Examples: If line x is selected then i need the value of the field with coordinates (1,x)
If line y is selected i need the value on the field (1,y)

Also on my dbgrid1.datasource.dataset. there is not 'fieldbyname'

Thanks.
Well we'll need to know what dataset you're using. Follow the process:
Click on your DBGrid. In the Object Inspector check what the value of the property  Datasource is, for example it might be DataSource1.
Find and select DataSource1.
In the Object Inspector, check for the value of the property under 'Dataset', for example ADOTable1.
Find and select ADOTable1.
In the Object Inspector, at the top it should say something like:
ADOTable1 TADOTable
The information I'm looking for is 'TADOTable' - the Type of the Object. In the case of TADOTable I know you're using an ADODataset
I am using as dataset on my datasource a adoquery.
My dbgrid is linked to a datasource that is linked to a adoquery
TADOQuery does have a FieldByName property. Please check again
indeed. Thanks a lot..
sorry for being dumb xD