Board index » delphi » value of a specific cell in a dbgrid

value of a specific cell in a dbgrid

hello

I'm trying to get the value of a specific cell in a dbgrid component. I
fill
the dbgrid using a query. Then the user selects a cell, which I read
using:

DBGrid1.Selectedfield.asstring

now i need to get the value in the cell adjacent to the selected cell,
but
can't figure out how.

Thanks

 

Re:value of a specific cell in a dbgrid


Quote
Ian Jones <ijo...@olemiss.edu> wrote:

The helpfile has this to say about it -:)

SelectedIndex
Run-time only. The value of the SelectedIndex property returns the
index value of the currently selected field in the displayed dataset.
A value of 0 indicates the first field of the displayed dataset, 1 is
the second field, and so on.
SelectedIndex can be used as an index to Fields property array to
access a field in the dataset.

So if you want the adjacent field you could do something like this:

Value := DBGrid1.Fields[Selectedfield+1].asstring;

If you are looking for a specific field that the user must selcet
before you do anything about it this will let you know the field:

If DBGrid1.SelectedField.Name = 'Target' then begin
  Value := DBGrid1.Fields[Selectedfield+1].asstring;
end;

Quote
>hello

>I'm trying to get the value of a specific cell in a dbgrid component. I
>fill
>the dbgrid using a query. Then the user selects a cell, which I read
>using:

>DBGrid1.Selectedfield.asstring

>now i need to get the value in the cell adjacent to the selected cell,
>but
>can't figure out how.

>Thanks

Other Threads