设置了options的goRowSelect,发现用col时,此时的无论点到哪个列上,
其col都是0(即第一列的位置),不知道怎么会这样!由于我编的程序希望点中的行用不同颜色与其他行数据区分,所以选择了goRowSelect,
现在我希望点中某个cells,能够得到这个cells里的真实值,却发现用col得不到正确的
列数,请高手指教!
不胜感谢!
其col都是0(即第一列的位置),不知道怎么会这样!由于我编的程序希望点中的行用不同颜色与其他行数据区分,所以选择了goRowSelect,
现在我希望点中某个cells,能够得到这个cells里的真实值,却发现用col得不到正确的
列数,请高手指教!
不胜感谢!
列数:StringGrid1.Selection.Right - StringGrid1.Selection.Left
procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol,
ARow: Integer; var CanSelect: Boolean);
begin
showmessage(inttostr(acol));
end;
在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;
thank!