• cxGrid 锁定一行,让该行数据不能编辑


    在使用cxGrid时,由于设置了所有单元格都能编辑,

    但在特定的情况下,让某些行,根据一些列值条件,让该行整行锁定,不能编辑。

    研究了很久,在DevExpress官网上找到了相关的资料,因此,分享给大家。

    Dev官网的列子是这样的

    // DISABLE A ROW  整行禁止编辑
    procedure TForm1.cxGrid1DBTableView1Editing(Sender: TcxCustomGridTableView;
      AItem: TcxCustomGridTableItem; var AAllow: Boolean);
    var
      AKeyValue : Variant;
    begin
      AKeyValue := Sender.DataController.GetRecordId(Sender.Controller.FocusedRecordIndex);
      if (AKeyValue = '1351') or (AKeyValue = '1356') or (AKeyValue = '1384') then
        AAllow := False;
    end;

    // MAKING A ROW READ ONLY   让一行只读
    procedure TForm1.cxGrid1DBTableView1InitEdit(
      Sender: TcxCustomGridTableView; AItem: TcxCustomGridTableItem;
      AEdit: TcxCustomEdit);
    var
      AKeyValue : Variant;
    begin
    {  AKeyValue := Sender.DataController.GetRecordId(Sender.Controller.FocusedRecordIndex);
      if (AKeyValue = '1351') or (AKeyValue = '1356') or (AKeyValue = '1384') then
        AEdit.ActiveProperties.ReadOnly := True;}
    end;

    // MAKING A ROW LOOK LIKE DISABLED   让一行看起来禁止了
    procedure TForm1.cxGrid1DBTableView1StylesGetContentStyle(
      Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
      AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);
    var
      AKeyValue : Variant;
    begin
      AKeyValue := Sender.DataController.GetRecordId(ARecord.RecordIndex);
      if (AKeyValue = '1351') or (AKeyValue = '1356') or (AKeyValue = '1384') then
        AStyle := cxDisableStyle;
    end;

    在实际使用中,若要根据某列的值,控制该行是否可编辑,代码如下:

    procedure TForm1.cxGrid1DBTableView1Editing(Sender: TcxCustomGridTableView;

        AItem: TcxCustomGridTableItem; var AAllow: Boolean);
    begin

     //cxGrid1DBTableView1CanEdit 为cxGrid中某列,判断不为空时,设置该行不能编辑。
      if VarToStrDef(Sender.Controller.FocusedRecord.Values[cxGrid1DBTableView1CanEdit.Index], '') <> '' then
        AAllow := False;
    end;

    本帖为博主原创,转载请注明出处:http://www.cnblogs.com/K-R-/p/6913211.html

    谢谢!

  • 相关阅读:
    [RN] React Native 中使用 stickyHeaderIndices 实现 ScrollView 的吸顶效果
    [PHP] layui实现多图上传,图片自由排序,自由删除
    [RN] React Native 下拉放大动画
    [RN] React Native 实现 多选标签
    [RN] React Native 让 Flatlist 支持 选中多个值,并获取所选择的值
    [RN] React Native代码转换成微信小程序代码的转换引擎工具
    【python小练】0004
    【python小练】0001
    【python小练】0000
    【LeetCode】108. Convert Sorted Array to Binary Search Tree
  • 原文地址:https://www.cnblogs.com/K-R-/p/6913211.html
Copyright © 2020-2023  润新知