I need to get the value of the selected cell of a DBGrid in Delphi.
I have no idea how to do it. I tried dbGrid's OnMouseMove
pt : TGridCoord;
...
pt:=dbGrid.MouseCoord(x, y);
[Edited] I can use the OnCellClick to get the value of the cell with "Column.Field.AsString", but I want to get the value from the first column when I click on any column of that row.
Found it.
dbGrid.Fields[0].AsString
gets the value of the first column of the selected row.
procedure TForm1.DBGrid_DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumnEh; State: TGridDrawState);
const defaultCheckBoxFieldNumber = 1;
begin
if DBGrid.SelectedField.FieldNo = defaultCheckBoxFieldNumber then
....;
else
...;
end;
DBGrid.SelectedField.FieldNo
gets selected field on event DrawColumnCell
in TDBGrid
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With