1.在dbgrid里我选中一行,然后点按纽处理,处理完该行变色,这个变色怎么处理。
2.我把dgRowSelect,dgMutiSelect设置为true, 然后用dbgrid.SelectedRows.Clear;和dbgrid.SelectedRows.Delete怎么都无法清除表格中选中的行?

解决方案 »

  1.   

    改变选中行的颜色DBGrid1.Options:=DBGrid1.Options+[dgRowSelect];procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    begin
     with DBGrid1 do
       begin
       if gdSelected in State  then
         Canvas.Brush.Color:=clRed
       else
         Canvas.Brush.Color:=clWhite;
       Canvas.FillRect(Rect);
       DefaultDrawColumnCell(Rect,DataCol,Column,State);
      end;
    end;
      

  2.   

    你设置一个变量,记录是否要修改颜色,例如CanChange bool;
    当你点按钮后,canchange := true;
    DBGrid1.Options:=DBGrid1.Options+[dgRowSelect];procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    begin
     if canchange then
    begin
     with DBGrid1 do
       begin
       if gdSelected in State  then
         Canvas.Brush.Color:=clRed
       else
         Canvas.Brush.Color:=clWhite;
       Canvas.FillRect(Rect);
       DefaultDrawColumnCell(Rect,DataCol,Column,State);
      end;
    end;
    end;
      

  3.   

    加个标志变量:
    var flag:boolean=False;OnDrawColumnCell事件:if flag then
     改变颜色Button的OnClick事件:flag:=True;
    DBGrid1.Repaint;
    flag:=False;
      

  4.   

    将DBgird->properties->options->dbrowselect改为true,默认颜色是clblue,
      

  5.   

    多谢liangqingzhi(老之),wudi_1982(︻┳═一)以及hhzqf1980(hh)
    问题1基本已解决,现在我选中某行,点确定确实能改变颜色。但是再选中另一行,改变颜色的那行又恢复了,怎样能不恢复呢?
    还有问题2请求答案,也就是处理完直接从Grid里清除掉也可以。