http://www.cnblogs.com/Kim53622744/p/4428997.html

在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.

Delphi cxgrid 使用方法
1.绑定数据
方法
cxGrid1DBTableView1.DataController.DataSource:=DataSource1
2.去掉"Drag   a   column   header   here   to   group   by   that   column"
方法
cxGrid1DBTableView1.OptionsView.GroupByBox置为False
3.去掉表头下三角数据 
方法
cxGrid1DBTableView1.Optionscustomize.columnfiltering置为False
4.增加序号
方法
在dataset 里边增加 Mycount 字段 类型为 string
在 CXgrid 增加显示字段 序号 mycount
为该字段写事件
procedure Tfrm_form.ReDataSet2mycountGetText(Sender: TField;
  var Text: String; DisplayText: Boolean);
begin
  inherited;
  text:=inttostr(redataset2.RecNo);
end;

将 序号 绑定 字段 Mycount

5.CXgrid 增加一栏显示checkBox
方法
在dataset 里边增加 MySelect字段 类型为 BOOLEAN

在 CXgrid 增加显示字段 选择 select

设定select 字段的Properties为 CheckBox .  ReadOnly = False;
NullStyle = nssUnchecked

procedure Tfrm_form.cxGrid1DBTableView1CellClick(
  Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
var
  Row: Integer;
begin
  inherited;

if ACellViewInfo.Item.Name = 'mycheck' then
  begin
    Row := cxGrid1DBTableView1.DataController.FocusedRecordIndex;
    if cxGrid1DBTableView1.ViewData.Records[Row].Values[0] = True then
      cxGrid1DBTableView1.ViewData.Records[Row].Values[0] := False
    else
      cxGrid1DBTableView1.ViewData.Records[Row].Values[0] := True;
  end;

end;

procedure Tfrm_form.cxGrid1DBTableView1MouseUp(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  Row: Integer;
begin
  inherited;
  //单选
  // for Row:=0 to  cxGrid1DBTableView1.DataController.RecordCount-1 do
  // begin
  //   cxGrid1DBTableView1.ViewData.Records[Row].Values[0] := False;
  // end;
  //多选
    if  cxGrid1DBTableView1.DataController.RecordCount<>0 then
  begin
   Row := cxGrid1DBTableView1.DataController.FocusedRecordIndex;

if cxGrid1DBTableView1.ViewData.Records[Row].Values[0] = True then
    cxGrid1DBTableView1.ViewData.Records[Row].Values[0] := False
  else
    cxGrid1DBTableView1.ViewData.Records[Row].Values[0] := True;
  end;
end;

cxGrid之checkbox小结的更多相关文章

  1. cxGrid增加一栏显示checkBox的设置方法

    鉴于本人首次设定cxGrid的CheckBox的时候费了很大劲,发现很多人都会碰到这个问题,现在总结一下,以供各位互相学习借鉴. 步骤如下(不分先后): 1. cxGrid添加完自己所需的所有字段后, ...

  2. Delphi - cxGrid设定字段类型为CheckBox

    cxGrid设定字段类型为CheckBox 1:设定OraQuery属性 CachedUpdates设定为True: 双击打开OraQuery,选中Update SQLs页面,Insert.Updat ...

  3. checkbox在vue中的用法小结

    关于checkbox多选框是再常见不过的了,几乎很多地方都会用到,这两天在使用vue框架时需要用到checkbox多选功能,实在着实让我头疼,vue和原生checkbox用法不太一样,之前对于vue插 ...

  4. 关于 cxGrid 的过滤问题

    http://bbs.csdn.net/topics/390536919 关于 cxGrid 的过滤问题 [问题点数:20分,结帖人zhengyc653]             不显示删除回复   ...

  5. DevExpress控件的GridControl控件小结

    DevExpress控件的GridControl控件小结 (由于开始使用DevExpress控件了,所以要点滴的记录一下) 1.DevExpress控件组中的GridControl控件不能使横向滚动条 ...

  6. delphi cxgrid 使用方法

    delphi cxgrid 使用方法1.绑定数据 方法 cxGrid1DBTableView1.DataController.DataSource:=DataSource12.去掉"Drag ...

  7. cxGrid的使用方法

    来源 http://www.cnblogs.com/djcsch2001/archive/2010/07/19/1780573.html   1.  去掉GroupBy栏 cxGrid1DBTable ...

  8. android基础小结

    (注:此小结文档在全屏模式下观看效果最佳) 2016年3月1日,正式开始了我的android学习之路. 最最开始的,当然是学习怎样搭载环境了,然而苦逼的我在win10各种坑爹的指引下还是安装了一个星期 ...

  9. 1:CSS中一些@规则的用法小结 2: @media用法详解

    第一篇文章:@用法小结 第二篇文章:@media用法 第一篇文章:@用法小结 这篇文章主要介绍了CSS中一些@规则的用法小结,是CSS入门学习中的基础知识,需要的朋友可以参考下     at-rule ...

随机推荐

  1. Ubuntu下实现gedit支持nesC语法高亮

    在TinyOS下主要采用nesC语言(C语言的一个变种)编程,ubuntu系统默认打开文本的工具是gedit,为实现gedit支持nesC语法高亮,将最下面的代码保存为nesC.lang文件,然后将n ...

  2. 清晰易懂!关于PS入门的超详细笔记!

    给大家分享一篇关于PS入门的超详细笔记!原理讲解清晰明了,虽不是新版本解析,但都是新手学习PS必掌懂的一些知识点,灰常的实用,转走收藏学习! 编辑:千锋UI设计 来源:PS学堂

  3. Spring MVC 注解类型

    Spring 2.5 引入了注解 基于注解的控制器的优势 1. 一个控制器类可以处理多个动作,而一个实现了 Controller 接口的控制器只能处理一个动作 2. 基于注解的控制器的请求映射不需要存 ...

  4. Spring访问数据库(方式上跟HQL类似,每行记录映射一个实体类)

    看了这篇技术博客,觉得收获较大,收藏了:http://sarin.iteye.com/blog/875915

  5. 什么是DevOps?DevOps简明教程

    我希望每个测试人员经过..功能测试-接口测试-安全测试-自动化测试-性能测试的洗礼后 都可以进入DevOps阶段.具体什么以及为什么 我稍后会给你大家讲解...

  6. 修改电脑自动休眠时间win10

    https://jingyan.baidu.com/article/adc81513a481cdf723bf73e6.html

  7. STL基础1:vector

    #include <iostream> #include <vector> #include <algorithm> #include <numeric> ...

  8. 27、Label 自适应文本 xib

    第一步: 第二步: 第三步: 第四步:

  9. SQL中datetime和timestamp的区别

    在开发一个简单的报名程序时,要求在每一条新插入的记录后面添加一个日期字段,方便日后查询和排序.于是立即百度,发现可以使用datetime或timestamp两种日期类型来实现.这对于爱纠结的我来说是不 ...

  10. 2018.12.31 bzoj3992: [SDOI2015]序列统计(生成函数+ntt+快速幂)

    传送门 生成函数简单题. 题意:给出一个集合A={a1,a2,...as}A=\{a_1,a_2,...a_s\}A={a1​,a2​,...as​},所有数都在[0,m−1][0,m-1][0,m− ...