dbgrid本来就有多选功能 options属性中 dgMultiSelect More than one row in the grid can be selected at a time. 或者可以采用所有者自绘的办法 先增加计算字段,在dbgrid事件onDrawColumnCell写显示checkbox的语句 这里以时间控件为例edtsj为TDateTimePicker procedure TFrmQCKC.gridDrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); begin edtsj.Hide; if column.Field.DataType<>ftdatetime then exit; if ((sender as tdbgrid).DataSource.DataSet as tadoquery).LockType=ltreadonly then exit; if not (gdSelected in state) then exit; edtsj.Parent:=column.Grid.Parent; edtsj.Date:=column.Field.AsDateTime; edtsj.Show; edtsj.Left:=column.Grid.Left+rect.Left+1; edtsj.Top:=column.Grid.Top+rect.Top+1; edtsj.Width:=rect.Right-rect.Left+1; edtsj.Height:=rect.Bottom-rect.Top+2; end;
是不是多条件组合查询啊?如果是,用SQL语句查询,DBGrid也会显示符合条件的结果啊! SQL='Select * from 数据表名 where'if CheckBox1.Checked =true then begin dd(0)=true sql=sql + 'CheckBox1所指的字段 ='+ '输入条件值' end if CheckBox2.Checked =true then begin dd(1)=true if dd(0) then //CheckBox1已选中 sql=sql + 'and CheckBox2所指的字段 ='+ '输入条件值' else //CheckBox1未选中 sql=sql + 'CheckBox2所指的字段 ='+ '输入条件值' end if not dd(0) or dd(1) then messagebox('请选择查询方式')
http://community.csdn.net/Expert/topic/3844/3844330.xml?temp=.2971613
然后再过滤值为‘*’的记录,可以吗?
options属性中
dgMultiSelect More than one row in the grid can be selected at a time.
或者可以采用所有者自绘的办法
先增加计算字段,在dbgrid事件onDrawColumnCell写显示checkbox的语句
这里以时间控件为例edtsj为TDateTimePicker
procedure TFrmQCKC.gridDrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin edtsj.Hide; if column.Field.DataType<>ftdatetime then exit;
if ((sender as tdbgrid).DataSource.DataSet as
tadoquery).LockType=ltreadonly then exit;
if not (gdSelected in state) then exit;
edtsj.Parent:=column.Grid.Parent;
edtsj.Date:=column.Field.AsDateTime;
edtsj.Show;
edtsj.Left:=column.Grid.Left+rect.Left+1;
edtsj.Top:=column.Grid.Top+rect.Top+1;
edtsj.Width:=rect.Right-rect.Left+1;
edtsj.Height:=rect.Bottom-rect.Top+2;
end;
SQL='Select * from 数据表名 where'if CheckBox1.Checked =true then
begin
dd(0)=true
sql=sql + 'CheckBox1所指的字段 ='+ '输入条件值'
end
if CheckBox2.Checked =true then
begin
dd(1)=true
if dd(0) then //CheckBox1已选中
sql=sql + 'and CheckBox2所指的字段 ='+ '输入条件值'
else //CheckBox1未选中
sql=sql + 'CheckBox2所指的字段 ='+ '输入条件值'
end
if not dd(0) or dd(1) then
messagebox('请选择查询方式')
但是,如果用前者的话,要不连接为CheckBox一列的那个字段类型设为Bit型,
都可以实现的,
你自己44吧,