我在做一个在dbgrid中查找的程序,当dbgrid中某格的内容与查找内容相符时,让它呈选中状态,怎样写代码呢?它所在行与列我都知道了
谢谢!

解决方案 »

  1.   

    dbgrid1.Options := dbgrid1.Options + [dgRowSelect];
    DBGrid1.SelectedRows.CurrentRowSelected:=true;
      

  2.   

    DBGrid1.DataSource.DataSet.Locate(...); //定義行
      DBGrid1.SelectedIndex:=2;  //定義列
      

  3.   

    能不能模拟在dbgrid中的某格单击呢?
    有谁做过吗?
      

  4.   

    有个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
      

  5.   

    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;这是我写的,光标定位在某一单元格,显示粉红色,你可以参考!
      

  6.   

    其实我们很多时候都应该对数据集操作而不是dbgrid
    在数据集中找到你要的记录后
    TDrawGrid(DBGrid1).Col:=i;(i为列号)
    DBGrid1.SetFocus;
    很简单就行了!
      

  7.   

    给个简单的例子吧,希望能帮上忙  
     if trim(edit1.Text)<>'' then
       begin
         SystemData.tbSCode.Locate('汉字',edit1.Text,[]);
         DBGrid1.SetFocus;
       end;