zoukankan      html  css  js  c++  java
  • 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;
     
     
    cxGrid 锁定一行,只能编辑该行数据
     
    cxGrid中如何把鼠标锁定在一行上,不能让它上下移动,在浏览状态下用户可以上下移动记录,但执行"修改"后就把鼠标锁定在当前修改的记录上,直接执行"保存"后才解除锁定.

    在TcxGridDBTableView的OnCanFocusRecord事件中写代码就行了.如下:

    procedure TFrmBillType.tvBillTypesCanFocusRecord(
      Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
      var AAllow: Boolean);
    begin
      inherited;
      if bUInEdit then
        AAllow := false;
    end;
    转载于:https://www.cnblogs.com/K-R-/p/6913211.html
  • 相关阅读:
    HYSBZ 1797 Mincut 最小割
    CodeForces 820B + 821C
    Codeforces 817+818(A~C)
    codeforces 816B Karen and Coffee (差分思想)
    840. Magic Squares In Grid ——weekly contest 86
    Linux 环境下 C++ 的开发编译
    838. Push Dominoes —— weekly contest 85
    836. Rectangle Overlap ——weekly contest 85
    六度空间
    835. Image Overlap —— weekly contest 84
  • 原文地址:https://www.cnblogs.com/kinglandsoft/p/12123931.html
Copyright © 2011-2022 走看看