Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

C++ Builder 6 - Getting a value from a DBGrid

Hi,

How can I do the following?
I have a DBGrid and I need to get values that grid.
When I click on a cell in the grid, I need to get all values in the selected row.
If for example there are 3 columns named ID, name and age.
If I click a cell in the grid, the value for the Id is displayed in a textbox, the value for name in another one and also the value for age in another textbox.
That is I need to display individual column values for the selected row in a text box for each one.

Can anyone help me?

Thanks.
Rowin
[570 byte] By [rowin] at [2007-11-11 8:49:08]
# 1 Re: C++ Builder 6 - Getting a value from a DBGrid
int size = DataSet->RecordSize;
char* ptr = new char[size];
DataSet->GetCurrentRecord(ptr);
//ptr now contains the whole record for the current row
delete [] ptr;

If you want values for the individual fields I think you should use FieldValues property :
TextBox1->Text = IntToStr(DataSet->FieldValues['ID']);//ID is a field name containing int values

This assumes that DBGrid is bound to DataSet
Ivan** at 2007-11-11 21:00:59 >