cxGrid之checkbox小结


在cxgrid中增加选择列

1、在dataset(query/table/clientdataset etc.)fieldeditor中增加计算字段fdSelect,datatype 为string,当然也可以其它类型。fieldkind设为fkCalculated或fkInternalCalc;设为fkInternalCalc时,应当注意在选择语句如下写:select '0' as fdselect,* from tableA,否则会报field "***" not found。设为fkCalculated时,不需要改变原语句。

object strngfldWaitInfdselect: TStringField
      FieldKind = fkInternalCalc
      FieldName = 'fdselect'
    end

2、cxgrid DbTableView中增加列cxgrdbclmnSelect,设置Properties为checkbox,具体设置如下:

object cxgrdbclmnSelect: TcxGridDBColumn
        Caption = #36873#25321
        DataBinding.FieldName = 'fdSelect'
        PropertiesClassName = 'TcxCheckBoxProperties'
        Properties.DisplayGrayed = 'nssUnchecked'
        Properties.ValueChecked = '1'
        Properties.ValueGrayed = 'nssUnchecked'
        Properties.ValueUnchecked = '0'
        MinWidth = 25
        Options.Editing = False  //重要,许多朋友讲到,不响应cellClick事件,设为false后就可响应。
        Options.Filtering = False
        Options.IncSearch = False
      end

3、根据需要在CellClick或mouseup中增加代码

var
  row: Integer;
begin
  if cxgrdbtblvwGrid1DBTableView1.ViewData.RecordCount = 0 then
    Exit;
  row := cxgrdbtblvwGrid1DBTableView1.DataController.FocusedRowIndex;
  if cxgrdbtblvwGrid1DBTableView1.ViewData.Records[row].Values[0] = '1' then
    cxgrdbtblvwGrid1DBTableView1.ViewData.Records[row].Values[0] := '0'
  else
    cxgrdbtblvwGrid1DBTableView1.ViewData.Records[row].Values[0] := '1';
end;

4、f9看下效果。

 

PS:fkCalculated与fkInternalCalc

Fields calculated by SQL servers or the Borland Database Engine to display the results of a query that returns a live dataset have a FieldKind of fkInternalCalc, not fkCalculated. This is because the field values are stored in the dataset. Calculated fields in a client dataset that are calculated in an event handler but stored in the dataset also have a FieldKind of fkInternalCalc instead of fkCalculated. Unlike regular calculated fields, internally calculated fields can be used in filter expressions. They can be edited, but the changes are discarded. To prevent editing, set the property to true.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值