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

谢谢!

转载于:https://www.cnblogs.com/K-R-/p/6913211.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值