I am trying to set the value of a column cell from a combobox. I have the following
The grid has columns Id, Name , Reference, quite simple.
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);
}
}
I can see the drop down and select a value, but the value is not saved in the cell and if i add a new row the value is cleared. Any advice on what is wrong ?