2
I would like to know how to catch the event click
of any line, returned from the GridView
.
For example, the GridView
shows me 3 lines, I want to click one of these lines and perform a certain action.
2
I would like to know how to catch the event click
of any line, returned from the GridView
.
For example, the GridView
shows me 3 lines, I want to click one of these lines and perform a certain action.
1
Look for the event onClick
on the pick of Object Inspector.
By clicking on the Grid it already arrow in the database record, then you can capture the id
and take the test.
procedure Tfrm.DBGri1Click(Sender: TObject);
begin
case TQuery.fieldbyname('id').asInteger of
1:;
2:;
end;
end;
Assuming the returned lines were:
Supposing the rows returned outside: id name age 1 Joao 23 2 josé 34 3 maria 43 ai I want to click on josé and get its id to compare in a case
connected on which component of database?
In a Tquery with a Datasource
why when clicking on the Grid it already arrow in the database record, then Voce can capture the id and do the test.
I’ll edit my answer
1
Another alternative is to use the event OnCellClick
, it is fired when the user clicks on some cell of the grid.
Take an example:
procedure TForm1.DBGrid1CellClick(Column: TColumn);
var
ID: integer;
begin
ID := DBGrid1.Fields[0].AsInteger; // Pega a o valor da primeira coluna selecionada
case ID of
1: ShowMessage('João');
2: ShowMessage('José');
3: ShowMessage('Maria');
else
ShowMessage('Nome desconhecido!');
end;
end;
Yes, but this method would be more appropriate if you take advantage of Column: Tcolumn if you don’t mind.
@Gabriellocalhost Yes, for example if you want to get the selected value independently of the column: ShowMessage(Column.Field.AsString)
.
That’s right, I usually wear it anyway
Browser other questions tagged delphi
You are not signed in. Login or sign up in order to post.
but what action you want to perform?
– GabrielLocalhost
Suppose the rows returned outside: 'id name age 1 Joao 23 2 josé 34 3 maria 43' , then I want to click on josé and get your id to compare in a case
– Lord Voldemort