With the OnClick event set on a several TeeGrids in a form I am able to deduce which TeeGrid on the form was clicked but do not see how to get which cell was clicked.
I changed it to OnSelect and can now tell which cell is selected but the Sender comes back as TVCLTeeGrid instead of TTeeGrid and I am unable to determine which TeeGrid was clicked.
I can add the OnClick event back in to get the which TeeGrid was clicked and then get the cell info from the OnSelect event but that seems a bit complicated and has some side effects of the cell not showing selected visually for all coluns.
Is there a better solution? What am I missing?
Event handling
Re: Event handling
Hello,
Using the OnClick event, you could do something like this:
And with OnSelected event, you could do it as follows:
Using the OnClick event, you could do something like this:
Code: Select all
procedure TTickerForm.TeeGridClick(Sender: TObject);
var Grid: TTeeGrid;
Col: TColumn;
ColIndex, RowIndex: Integer;
CursorPos: TPoint;
begin
if Sender is TTeeGrid then
begin
Grid:=Sender as TTeeGrid;
if Grid = TeeGrid1 then
Label2.Caption:='TeeGrid1 clicked'
else if Grid = TeeGrid2 then
Label2.Caption:='TeeGrid2 clicked';
CursorPos:=Grid.ParentToClient(CalcCursorPos);
Col:=Grid.Columns.FindAt(CursorPos.X, TeeGrid1.Width);
RowIndex:=Grid.Rows.RowAt(CursorPos.Y, TeeGrid1.Height);
ColIndex:=-1;
repeat
Inc(ColIndex);
until (ColIndex=Grid.Columns.Count) or (Grid.Columns[ColIndex]=Col);
if ColIndex<Grid.Columns.Count then
Label2.Caption:=Label2.Caption + ', Col: ' + IntToStr(ColIndex) + ', Row: ' + IntToStr(RowIndex);
end;
end;
Code: Select all
procedure TTickerForm.TeeGrid1Select(Sender: TObject);
var ColIndex: Integer;
begin
Label2.Caption:='';
if Sender = TeeGrid1.Grid then
begin
Label2.Caption:='TeeGrid1 selected';
end
else if Sender = TeeGrid2.Grid then
begin
Label2.Caption:='TeeGrid2 selected';
end;
with (Sender as TVCLTeeGrid).Root do
begin
ColIndex:=-1;
repeat
Inc(ColIndex);
until (ColIndex=Columns.Count) or (Columns[ColIndex]=Selected.Column);
if ColIndex<Columns.Count then
Label2.Caption:=Label2.Caption + ', Col: ' + IntToStr(ColIndex) + ', Row: ' + IntToStr(Selected.Row);
end;
end;
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |