Delphi

cxGrid设定字段类型为ComboBox

在cxGrid中选中需要设定的字段;

单击F11调出属性控制面板,在Properties下拉选项中选中ComboBox,完成字段类型的设定。

cxGrid ComboBox类型字段动态赋值,添加Item

动态赋值代码如下:

1 TcxComboBoxProperties(cxGrid1DBTableView1GROUPNAME.Properties).Items.Text := value;

动态添加Item代码如下:

procedure ComboAdd(Sender: Tstrings; SQLStr, v_Param: string);
begin
    ComboAddEx(MainForm.OraSession1, Sender, SQLStr, v_Param);
end;

procedure ComboAddEx(v_Session: TOraSession; Sender: Tstrings; SQLStr, v_Param: string);
var
    i, r: Integer;
    Q: ToraQuery;
    S: tstringlist;
begin
    s := tstringlist.Create;
    s.Clear;
    Q := ToraQuery.Create(nil);
    Q.Session := v_Session;
    OpenQuery(Q, SQLStr);
    SetParam(Q, v_Param);
    Q.Open;
    Q.first;
    while not Q.Eof do
    begin
        Sender.Add(Q.Fields[0].AsString);
        Q.next;
    end;
    Q.Close;
    Q.Free;
end;

//动态加载Item
var
    zm: TRzComboBox;
begin
    MainForm.dxBarListWindows.Items.AddObject(Caption, self);
    zm: TRzComboBox;
    zm.Items.Clear;
    ComboAdd(zm.Items, 'select DISTINCT FiledName from TableName t', '');
  TcxComboBoxProperties(cxGrid1DBTableView1FieldName.Properties).Items.Text := zm.Items.Text;
    zm.ItemIndex := 0;
    zm.OnClick(self);
end;

  作者:Jeremy.Wu
  出处:https://www.cnblogs.com/jeremywucnblog/
  本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

原文地址:https://www.cnblogs.com/jeremywucnblog/p/11422687.html