设置了options的goRowSelect,发现用col时,此时的无论点到哪个列上,
其col都是0(即第一列的位置),不知道怎么会这样!由于我编的程序希望点中的行用不同颜色与其他行数据区分,所以选择了goRowSelect,
现在我希望点中某个cells,能够得到这个cells里的真实值,却发现用col得不到正确的
列数,请高手指教!
不胜感谢!

解决方案 »

  1.   

    用StringGrid1.Selection:
    列数:StringGrid1.Selection.Right - StringGrid1.Selection.Left
      

  2.   

    你试试在OnSelectCell事件中写代码:
    procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol,
      ARow: Integer; var CanSelect: Boolean);
    begin
      showmessage(inttostr(acol));
    end;
      

  3.   

    你希望当前行颜色与其它行不同可以这样写,把goRowSelect去掉,
    在OnDrawCell和OnSelectCell事件中:
    procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    begin
      with StringGrid1.Canvas do
      if ARow = StringGrid1.Row then begin
        Brush.Color := clYellow;  // 设置背景色
        FillRect(Rect);
        Font.Color := clBlack;    // 设置字体颜色
        TextOut(Rect.Left+2,Rect.Top+2, StringGrid1.Cells[ACol, ARow]);
      end;
    end;procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol,
      ARow: Integer; var CanSelect: Boolean);
    begin
      StringGrid1.Invalidate;  // 重画,产生OnDrawCell事件
    end;
      

  4.   

    谢谢,问题已经解决!
    thank!