stringgrid怎么选行啊
1个回答
2013-07-10
展开全部
1、这个问题小儿科。能用麻溜结贴,不能用就追问,别当没看到。2、解决思路。StringGrid是这样运作的:goRowSelect就是把某行背景涂上颜色,而goEditing是用一个Edit置于选中的Cell之上。狗屎Delphi自以为聪明,把编辑框对象封装了起来,所以从前者作为突破口要比后者简单得多。3、解决办法。将StringGrid的Options属性,goEditing设为True,goRowSelect设为False。然后在Form中加入如下代码:type TForm1 = class(TForm) StringGrid1: TStringGrid; procedure FormCreate(Sender: TObject); procedure StringGrid1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); private FSelRow: Integer; public { Public declarations } end; procedure TForm1.FormCreate(Sender: TObject); begin FSelRow := -1;end; procedure TForm1.StringGrid1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);var col, row: Longint;begin if Button = mbLeft then begin StringGrid1.MouseToCell(X, Y, col, row); if row FSelRow then begin FSelRow := row; StringGrid1.Repaint; end; end;end; procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);begin if (State = []) and (FSelRow = ARow) then begin StringGrid1.Canvas.Brush.Color := clYellow; StringGrid1.Canvas.FillRect(Rect); StringGrid1.Canvas.TextOut(Rect.left , Rect.top, StringGrid1.Cells[ACol, ARow]); end;end;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询