var row, col: Integer; sel: TGridRect; begin for row := 0 to StringGrid1.RowCount - 1 do begin for col := 0 to StringGrid1.ColCount - 1 do begin if StringGrid1.Cells[col, row] = Edit1.Text then begin sel.Left := col; sel.Top := row; sel.Right := col; sel.Bottom := row; StringGrid1.Selection := sel; end; end; end; end;
procedure Tfrmdata.sjgzgridMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var Column,Row:integer; begin if Button=mbRight then begin sjgzgrid.MouseToCell(X,Y,Column, Row); sjgzgrid.Col:=Column; sjgzgrid.Row:=Row; end; if Button=mbLeft then begin sjgzgrid.MouseToCell(X, Y, Column, Row); sjgzgrid.Col:=Column; sjgzgrid.Row:=Row; end; 上面的可以控制鼠标选中哪个行,你要选Cell,用2楼的那个TGridRect;
row, col: Integer;
sel: TGridRect;
begin
for row := 0 to StringGrid1.RowCount - 1 do
begin
for col := 0 to StringGrid1.ColCount - 1 do
begin
if StringGrid1.Cells[col, row] = Edit1.Text then
begin
sel.Left := col;
sel.Top := row;
sel.Right := col;
sel.Bottom := row;
StringGrid1.Selection := sel;
end;
end;
end;
end;
procedure Tfrmdata.sjgzgridMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
Column,Row:integer;
begin
if Button=mbRight then
begin
sjgzgrid.MouseToCell(X,Y,Column, Row);
sjgzgrid.Col:=Column;
sjgzgrid.Row:=Row;
end;
if Button=mbLeft then
begin
sjgzgrid.MouseToCell(X, Y, Column, Row);
sjgzgrid.Col:=Column;
sjgzgrid.Row:=Row;
end;
上面的可以控制鼠标选中哪个行,你要选Cell,用2楼的那个TGridRect;