怎样在StringGrid动态撞见CheckBox,可以实现多选。

解决方案 »

  1.   

    StringGrid好像只支持连续多选吧
    动态隔行多选好像不能支持
    还有,那个词是创建不是撞见吧?
      

  2.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, Buttons, DBCtrls, Grids;type
      TForm1 = class(TForm)
        StringGrid1: TStringGrid;
        procedure FormCreate(Sender: TObject);
        procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
          Rect: TRect; State: TGridDrawState);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
    var i:Integer;
    begin
       for i:=1 to 4 do
       begin
         StringGrid1.Cells[0,i]:=IntToStr(i);
         if i mod 2=0 then
           StringGrid1.Cells[1,i]:='True'
         else StringGrid1.Cells[1,i]:='False';
       end;
    end;procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    begin
       if (ARow>0) and (ACol=2) then
       begin
         StringGrid1.Canvas.FillRect(Rect);
         if SameText(StringGrid1.Cells[ACol-1, ARow],'True') then
           DrawFrameControl(StringGrid1.Canvas.Handle, Rect, DFC_BUTTON, DFCS_BUTTONCHECK or DFCS_CHECKED)
         else DrawFrameControl(StringGrid1.Canvas.Handle, Rect, DFC_BUTTON, DFCS_BUTTONCHECK)
       end
       else StringGrid1.Canvas.TextRect(Rect, Rect.Left+2, Rect.Top+2, StringGrid1.Cells[ACol, ARow]);
    end;end.