请教:  
 
我们都知道如果把stringgrid的options选项里面的goselect  设置为true则可以选择整行但不能编辑单元格,现在问题是如何即要可以编号单元格(也就是goedit设置为true)又会出现一条蓝色的选择条?

解决方案 »

  1.   

    这个简单,就是在drawcell事件中加入你的代码就行了.
      

  2.   

    { Options选项里面的goRowSelect设置为True时,一直有一个蓝色长条,比较难以实现编辑内容.
    可以动态实现goRowSelect为真为假,当点击最左边的固定列时为真,否则为假.
    在OnMouseDown中实现 }
    procedure TForm1.StringGrid1MouseDown(Sender: TObject;
      Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    var
      SelectCol, SelectRow: Longint;
      SelectGrid: TGridRect;
    begin
      with StringGrid1 do
      begin
        MouseToCell(X, Y, SelectCol, SelectRow);
        if (SelectCol < FixedCols) and (SelectCol >= 0) then
        begin
          Options := Options + [goRowSelect];
          with SelectGrid do
          begin
            Left := LeftCol;
            Top := SelectRow;
            Right := ColCount - 1;
            Bottom := SelectRow;
            Selection := SelectGrid;
          end;
        end
        else
          Options := Options - [goRowSelect];
      end;
    end;