更改另一个时更改cxgrid中的字段值

时间:2013-03-31 00:30:40

标签: delphi devexpress delphi-xe2 delphi-xe

在我的cxGrid中,我有一个Yes / No字段,默认为'NO'。在该字段旁边,我有另一个字段,即LookupComboBox字段 从另一个表中获取其值。默认情况下它是空的,但是当我在这里改变了值时,我希望如此 特定字段,我的是/否字段应更改为“是”(仅在我当前正在编辑的行中)我该怎么做?还不确定在何处实现代码.... OnChange,Oneditvaluechanged,Onvalidate ???

1 个答案:

答案 0 :(得分:1)

由于您的网格semms要绑定在数据集上,因此一种简单的方法是使用选择字段的fieldchange事件。
对于直接行为,您应该使用TcxEditRepositoryLookupComboBoxItem和ImmediatePost而不是数据集中的Lookupfield(无论如何,至少ADO的方法更糟糕)

procedure TForm4.MainSelectionChange(Sender: TField);
begin

   if Main.State in [dsEdit,dsInsert] then
      if not Sender.IsNull then
        MainYesNo.Value := true;

   { maybe you are looking for that instead the code above
   if Main.State in [dsEdit,dsInsert] then
        MainYesNo.Value := not Sender.IsNull
   }
end;

Lookup definition Lookupusage