如何在Devexpress XtragGrid的组合框中设置列单元格的值?

问题描述

我正在尝试通过组合框设置列单元格的值。我有以下

表格中的ID,Name和Reference列非常简单。

 private void Form_Load(object sender,EventArgs e)
    {
       
        DataTable dt = GetData(); // populates correctly 
        if (dt.Rows.Count > 0)
        {
            //bind to the grid
            gridControl1.DataSource = dt;
        }                     
        riComboBox = new RepositoryItemComboBox();
        riComboBox.Items.AddRange(companies);
        gridControl1.RepositoryItems.Add(riComboBox);
        gridView1.Columns["Companies"].ColumnEdit = riComboBox;
       
    }
    
    
    
         public static string[] companies= new string[] {  "Company1","company2","company3","company4","company5","company6","company7","company8","company9","company10"};

    
    private void gridView1_CellValueChanging(object sender,DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
    {
        
        gridView1.ShowEditor();
        GridView view = sender as GridView;
        DevExpress.XtraGrid.Columns.GridColumn col = view.Columns.ColumnByFieldName("Companies");
        if (col == null) return;            
        gridControl1.BeginUpdate();
        try
        {
            gridView1.CellValueChanging -= new 
            DevExpress.XtraGrid.Views.Base.CellValueChangedEventHandler(gridView1_CellValueChanging);                                
            ComboBoxEdit edit = gridView1.ActiveEditor as ComboBoxEdit;
            if (edit != null)
            {
                string newValue = edit.Text;                   
                gridView1.SetFocusedValue(newValue);
                gridControl1.EndUpdate();
               
            }                
        }
        finally
        {
            gridView1.CellValueChanging += new 
            DevExpress.XtraGrid.Views.Base.CellValueChangedEventHandler(gridView1_CellValueChanging);                
        }
    }

我可以看到下拉列表并选择一个值,但是该值未保存在单元格中,如果我添加新行,则该值将被清除。有什么问题的建议吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...