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. Django 访问admin提示ViewDoesNotExist at /admin/

    ViewDoesNotExist at /admin/ Could not import django.views.generic.simple.redirect_to. Parent module ...

  2. NC 6系后台调用接口保存单据

    IPFBusiAction ipf = (IPFBusiAction)NCLocator.getInstance().lookup(IPFBusiAction.class); ipf.processA ...

  3. linux 软件编译问题汇总

    1.问题: fatal error: openssl/opensslv.h: No such file or directory 解决: sudo apt-get install libssl-dev ...

  4. Spring 注解驱动(一)基本使用规则

    Spring 注解驱动(一)基本使用规则 Spring 系列目录(https://www.cnblogs.com/binarylei/p/10198698.html) 一.基本使用 @Configur ...

  5. EditText输入小数

    edtValue.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);

  6. 复制粘贴容易犯的错误 eclipse

    有时候复制原有的代码到xml文件中,会提示某文件没有找到,一般该文件名字改成别的了,这时候为了解决这问题一般需要对这个文件重命名

  7. Sharing Code Between Silverlight and Win8 app metro

    这里讲得很详细了: Sharing Code between Windows Phone 8 and Windows 8 Applications http://msdn.microsoft.com/ ...

  8. TensorFlow安装时错误CondaValueError: prefix already exists: G:\softs\Anaconda\envs\tensorflow

    TensorFlow安装时,TensorFlow环境已经调好了,就是下面的第(3)步, 可我自己偏偏选了个Python3.7,因为检测到自己的Python最新版本为3.7,就手贱安了TensorFlo ...

  9. 【转】MongoDB导入导出以及数据库备份

    -------------------MongoDB数据导入与导出------------------- 1.导出工具:mongoexport     1.概念:         mongoDB中的m ...

  10. Jersey RESTful WebService框架学习(六)接收MultivaluedMap类型参数

    现在的web开发中有些工程会觉得实体bean的架构会比较重,现在的持久层的框架的特点也层出不穷,核心思想的ORM在此基础上,提供了很多便捷操作,mybatis,jfinal(内部持久层框架)之类的也诞 ...