Set hint for cells of StringGrid

Posted in Components

This example shows, how to check a cursor moving in StringGrid component and how to show hint for each cell with coordinates of this cell.

procedure TForm1.FormCreate(Sender: TObject);
begin
  StringGrid1.Hint:= '0 0';
  StringGrid1.ShowHint:= True;
end;

procedure TForm1.StringGrid1MouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Integer);
var
  R, C: Integer;
begin
  StringGrid1.MouseToCell(X, Y, C, R);
  with StringGrid1 do
  begin
    if ((Row<>R)or(Col<>C)) then
    begin
      Row:=R;
      Col:=C;
      Application.CancelHint;
      StringGrid1.Hint:=IntToStr(R)+#32+IntToStr(C);
    end;
  end;
end;