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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
There is also a way to refer to the first column by number instead of by name, try something like this:
MyDataset.Fields[0].AsStri ng;
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
MyDataset.Fields[0].AsStri
Here's another trick. You can refer to your dataset indirectly by going through the DBGrid:
DBGrid1.Datasource.Dataset
Note the 'AsString' part - you have other options like .value, .AsInteger, .AsFloat, .AsCurrency, .AsBoolean etc
ASKER
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.
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
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
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
ASKER
I am using as dataset on my datasource a adoquery.
My dbgrid is linked to a datasource that is linked to a adoquery
My dbgrid is linked to a datasource that is linked to a adoquery
TADOQuery does have a FieldByName property. Please check again
ASKER
indeed. Thanks a lot..
ASKER
sorry for being dumb xD
ASKER