微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决如何在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 举报,一经查实,本站将立刻删除。