我用下面的方法创建里一组checkbox在stringgrid里面 可是创建以后的checkbox 点击无效啊 就是无法用鼠标改变其 checked 属性 但是如果 cbList[i].Parent:=Form1; 就可以正长点击了,这在StringGrid里该怎么做呢?
还有 cbList[i].Parent:=StringGrid1;时候 连onclick事件也不响应了 form1里
就可以的, 还有动态控件数组的事件里如何区分他们的 对应的是哪个控件呢 ?
就是 我click一下 怎么知道这是 数组里具体哪个对象呢?
因为cbList[i].Parent:=Form1 我就无法准确控制checkbox在stringgrid中的位置了
所以只有用此办法了
for i :=0 to Length(cbList)-1 do
begin
cbList[i]:=TcheckBox.Create(StringGrid1);
cbList[i].Create(StringGrid1);
cbList[i].Name :='cb'+inttostr(i);
cbList[i].Parent:=StringGrid1; //zheli
cbList[i].Width :=20;
cbList[i].OnClick:=CheckboxClik;
cbList[i].Caption:='';
cbList[i].Top :=i*22+1;
cbList[i].left :=100 ;
end;
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, StdCtrls;type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
Button3: TButton;
private
{ Private declarations }
public
cbList:array of TCheckBox;
procedure CheckboxClik(sender:TObject);
end;
。。
procedure TForm2.CheckboxClik(sender: TObject);
var i:integer;
begin 这里如何知道响应哪个对象的事件呢
cbList[i].Parent:=StringGrid1时 这里还不响应怎么办法?
end;
还有 cbList[i].Parent:=StringGrid1;时候 连onclick事件也不响应了 form1里
就可以的, 还有动态控件数组的事件里如何区分他们的 对应的是哪个控件呢 ?
就是 我click一下 怎么知道这是 数组里具体哪个对象呢?
因为cbList[i].Parent:=Form1 我就无法准确控制checkbox在stringgrid中的位置了
所以只有用此办法了
for i :=0 to Length(cbList)-1 do
begin
cbList[i]:=TcheckBox.Create(StringGrid1);
cbList[i].Create(StringGrid1);
cbList[i].Name :='cb'+inttostr(i);
cbList[i].Parent:=StringGrid1; //zheli
cbList[i].Width :=20;
cbList[i].OnClick:=CheckboxClik;
cbList[i].Caption:='';
cbList[i].Top :=i*22+1;
cbList[i].left :=100 ;
end;
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, StdCtrls;type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
Button3: TButton;
private
{ Private declarations }
public
cbList:array of TCheckBox;
procedure CheckboxClik(sender:TObject);
end;
。。
procedure TForm2.CheckboxClik(sender: TObject);
var i:integer;
begin 这里如何知道响应哪个对象的事件呢
cbList[i].Parent:=StringGrid1时 这里还不响应怎么办法?
end;
解决方案 »
- delphi7导入导出求助
- 关于delphi中用热键实现象QQ一样的功能,而且能够使整个应用程序最大化
- 三层结构,我写了一个简单的测试程序,为什么客户端再次取数据会出错?
- 控件SPComm的异常如何处理
- TDBGridEh如何加入下拉框
- 运用EhLib中的dbguideh控件遇到的问题?
- Dll中如何访问主程序的datamodule中的共用变量与连接??
- 我想知道用DELPHI做开发一般有多少钱一个月(什么地方)?
- 程非编过不知难!
- delphi 登录时权限设置
- 大哥们给我一个邮件发送的程序(100分在线等)qq:80561109;email:[email protected]
- 求VOC格式声音文件转wav格式的方法,或直接用声卡播放VOC
让他显示,然后在combobox的onExit事件里面写stringGrid的值,就好了,很简单的,如果需要我写的一套控件里面可以实现,只要你设定combobox的item值,以后别的都是由我的控件来实现,如果需要,留下mail
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids;type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
procedure DrawCheckBox(ARect:TRect;IsChecked:Boolean);
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var lRect :Trect;
begin
if (Acol=1) and (Arow<>0) then
begin
if StringGrid1.Cells[aCol,ARow]='0' then
DrawCheckBox(Rect,False)
else
DrawCheckBox(Rect,True);
end;
end;procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol,
ARow: Integer; var CanSelect: Boolean);
var lRect :TRect;
begin
if (Acol=1) and (Arow<>0) then
begin
if StringGrid1.Cells[aCol,aRow]='0' then StringGrid1.Cells[aCol,aRow]:='1'
else StringGrid1.Cells[aCol,aRow]:='0';
end;
end;procedure TForm1.DrawCheckBox(ARect:TRect;IsChecked:Boolean);
var lRect :TRect;
begin
lrect := Classes.rect(0,0,12,12);
OffsetRect(lRect,ARect.Left,ARect.Top);
OffsetRect(lRect,(Arect.Right-ARect.Left-12) div 2,(Arect.Bottom-Arect.Top-12) div 2);
with StringGrid1 do
begin
Canvas.Brush.Color := Canvas.Brush.Color;
Canvas.FillRect(aRect);
Canvas.Brush.Color := clBlack;
Canvas.FrameRect(lRect);
if IsChecked then
begin
Canvas.Pen.Color := clBlack;
Canvas.Polyline([Point(lRect.Left,lRect.Bottom-5),Point(lRect.Left+4,lRect.Bottom-1),Point(lRect.Right,lRect.Top+3)]);
end;
end;
end;procedure TForm1.FormCreate(Sender: TObject);
var i:Integer;
begin
for i:=1 to StringGrid1.RowCount-1 do
StringGrid1.Cells[1,i]:= '0';
end;