上一个是单击stringgrid
这个是用一个按钮来。
procedure TForm1.BitBtn1Click(Sender: TObject);
var i,j:integer;
begin
//stringgrid.setfocus := false;
for I := 0 to stringgrid.ColCount do
for j:= 0 to stringgrid.rowcount do
stringgrid.cells[i,j]:= ''
end;
procedure TForm1.StringGridClick(Sender: TObject);
var i,j:integer;
begin
for I := 0 to stringgrid.ColCount do
for j:= 0 to stringgrid.rowcount do
stringgrid.cells[i,j]:= ''
end;
希望下面一段代码可以给你一点启发:
procedure TForm1.BitBtn1Click(Sender: TObject);
var
myRect: TGridRect;
begin
if StringGrid1.Col<StringGrid1.ColCount-1 then
begin
myRect.Left := StringGrid1.col+1;
myRect.Top := StringGrid1.row;
myRect.Right := StringGrid1.col+1;
myRect.Bottom := StringGrid1.Row;
end
else
if StringGrid1.Row<StringGrid1.RowCount-1 then
begin
myRect.Left := 1;
myRect.Top := StringGrid1.row+1;
myRect.Right := 1;
myRect.Bottom := StringGrid1.Row+1;
end;
if (StringGrid1.Row<StringGrid1.RowCount-1) or (StringGrid1.Col<StringGrid1.ColCount-1) then
begin
StringGrid1.Selection := myRect;
Application.MessageBox(PCHAR('当前行:'+IntToStr(StringGrid1.Row)+'当前列:'+IntToStr(StringGrid1.Col)),'提示',MB_OK);
end;
end;
在stringgrid1的onclick事件中加入下面代码:
procedure TForm1.StringGrid1Click(Sender: TObject);
var
row,col:Integer;
begin
row:=stringGrid1.row;
col:=stringgrid1.col;
if (row=2) and (col=3) then
stringGrid1.Options:=stringGrid1.Options-[goEditing]
else stringGrid1.Options:=stringGrid1.Options+[goEditing];
end;