有个ONDRAWCOLUMNCELL事件 编写程序,DBGRID中的单元中的值和你要的相等时,就把焦点给他 for i:=0 to DBGRID1.rowcount-1 do begin for j:=0 to DBGRID1.columncount-1 do begin if DBGRID1.CELLS[i.j]. = then
procedure TFrmsize.SG_sizeDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); begin with sg_size.Canvas do begin if State=[gdFixed] then Font.Style := Font.Style+[fsBold] else if (ACol mod 2)=1 then Brush.Color := $e8e8e8; FillRect(Rect); Font.Color := clBlue ; TextRect(Rect, Rect.Left+1, Rect.Top+1, sg_size.Cells[ACol, ARow]); if (acol=sgcol) and (arow=sgrow) then begin brush.Color :=clFuchsia ; FillRect(Rect); Font.Color := clBlue ; TextRect(Rect, Rect.Left+1, Rect.Top+1, sg_size.Cells[ACol, ARow]); end; end;end;这是我写的,光标定位在某一单元格,显示粉红色,你可以参考!
DBGrid1.SelectedRows.CurrentRowSelected:=true;
DBGrid1.SelectedIndex:=2; //定義列
有谁做过吗?
编写程序,DBGRID中的单元中的值和你要的相等时,就把焦点给他
for i:=0 to DBGRID1.rowcount-1 do
begin
for j:=0 to DBGRID1.columncount-1 do
begin
if DBGRID1.CELLS[i.j]. = then
Rect: TRect; State: TGridDrawState);
begin
with sg_size.Canvas do
begin
if State=[gdFixed] then
Font.Style := Font.Style+[fsBold]
else if (ACol mod 2)=1 then
Brush.Color := $e8e8e8;
FillRect(Rect);
Font.Color := clBlue ;
TextRect(Rect, Rect.Left+1, Rect.Top+1, sg_size.Cells[ACol, ARow]);
if (acol=sgcol) and (arow=sgrow) then
begin
brush.Color :=clFuchsia ;
FillRect(Rect);
Font.Color := clBlue ;
TextRect(Rect, Rect.Left+1, Rect.Top+1, sg_size.Cells[ACol, ARow]);
end;
end;end;这是我写的,光标定位在某一单元格,显示粉红色,你可以参考!
在数据集中找到你要的记录后
TDrawGrid(DBGrid1).Col:=i;(i为列号)
DBGrid1.SetFocus;
很简单就行了!
if trim(edit1.Text)<>'' then
begin
SystemData.tbSCode.Locate('汉字',edit1.Text,[]);
DBGrid1.SetFocus;
end;