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. java中 this 关键字的三种用法

    Java中this的三种用法 调用属性 (1)this可以调用本类中的任何成员变量 调用方法(可省略) (2)this调用本类中的成员方法(在main方法里面没有办法通过this调用) 调用构造方法 ...

  2. Python之路(第二十二篇) 面向对象初级:概念、类属性

    一.面向对象概念 1. "面向对象(OOP)"是什么? 简单点说,“面向对象”是一种编程范式,而编程范式是按照不同的编程特点总结出来的编程方式.俗话说,条条大路通罗马,也就说我们使 ...

  3. swift NSdata 转换 nsstring

    result = NSString(data: data, encoding: NSUTF8StringEncoding) 做HTTP 请求时 遇到 打印结果看  所以~~~

  4. vue input,textarea失去焦点调用函数方法

    <input type="number" class="num" value="1" @blur.prevent="chan ...

  5. SpringMVC学习笔记:表单提交 参数的接收

    SpringMVC可以接收原生form表单和json格式数据 有一个名为Book的model,其中的属性如下: 字符串类型的name,数字类型的price,数组类型的cover,集合类型的author ...

  6. Prism-超轻量的开源框架

    http://msdn.microsoft.com/en-us/library/ff648465.aspx prism 是微软模式与实践小组开发的一个进行MVVM模式开发,其中使用依赖注入等一些方法将 ...

  7. 执行sh脚本文件下载Github上的代码(雷霄骅的ffmpeg示例代码)

       今天想重新学习下ffmpeg,于是又来到了雷晓骅的博客,先下载了他的所有代码,这里记录一下在Windows上使用sh脚本下载GitHub上代码的过程. CygWin(最后并没有用到)    可以 ...

  8. Le Chapitre IX

    Je crois qu'il profita, pour son évasion[evazjɔ̃]逃跑, d'une migration d'oiseaux sauvages[sovaʒ]未驯化的. ...

  9. identify.class.php<======>token加密方法

    class Identify { static private $cert = "1111111"; static public function writeSecret($mob ...

  10. HDMI中checksum计算法

    在AVI传输过程中有三个字节没有被传输.这是在HDMI1.4B中找到的前三个字节的数据. >> hex2dec('82') ans = 130 下图中的数据中在HDMI中接收到的一串数据, ...