zoukankan      html  css  js  c++  java
  • cxGrid之checkbox小结

    cxGrid之checkbox小结

    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

      注:单选、多选属性设置:

      cxGrid1DBTableView1-->DataController-->DataModeController-->SmartRefresh : True(多选) False(单选)

      如果同时响应双击:

      cxGrid1DBTableView1-->OptionsBehavior-->ImmediateEditor : False(不会先进入编辑状态,这是才能相应双击事件) True(默认值,先进入编辑状态)

    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.

  • 相关阅读:
    [LeetCode] Largest Number At Least Twice of Others 至少是其他数字两倍的最大数
    [LeetCode] Cut Off Trees for Golf Event 为高尔夫赛事砍树
    [LeetCode] Kth Smallest Number in Multiplication Table 乘法表中的第K小的数字
    [LeetCode] 746. Min Cost Climbing Stairs 爬楼梯的最小损失
    [LeetCode] Prefix and Suffix Search 前后缀搜索
    [LeetCode] Strange Printer 奇怪的打印机
    VMPlayer Ubuntu 16.04 Copy and Paste with Host 主机与宿机之间的复制粘贴
    Solve Error: "errcode": 85005, "errmsg": "appid not bind weapp hint"
    [LeetCode] Find Smallest Letter Greater Than Target 找比目标值大的最小字母
    [LeetCode] 743. Network Delay Time 网络延迟时间
  • 原文地址:https://www.cnblogs.com/acmexyz/p/10427183.html
Copyright © 2011-2022 走看看