There are two columns in a grid placed in a windows form. The first column is a GridViewComboBoxColumn and the second one is a GridViewDataColumn. I have populated the combo box with values. I need to assign the selected value from the drop down to the cell on which it resides. The code i have written is given below.
private void BindData()
{
radGridView1.GridElement.BeginUpdate();
var gridViewLookUpColumn = ((GridViewLookUpColumn)(radGridView1.CurrentRow.Cells["column1"].ColumnInfo));
if (gridViewLookUpColumn == null) return;
gridViewLookUpColumn.DataSource = FillData();
gridViewLookUpColumn.DisplayMember = "Name";
gridViewLookUpColumn.ValueMember = "Id";
gridViewLookUpColumn.DropDownStyle = RadDropDownStyle.DropDownList;
radGridView1.GridElement.EndUpdate();
}
private static DataTable FillData()
{
var dt = new DataTable();
dt.Columns.Add(new DataColumn("Name", typeof(String)));
dt.Columns.Add(new DataColumn("Id", typeof(Int32)));
var dr = dt.NewRow();
dr["Name"] = "Test 1";
dr["Id"] = 1;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["Name"] = "Test 2";
dr["Id"] = "2";
dt.Rows.Add(dr);
return dt;
}
private void radGridView1_CellBeginEdit(object sender, GridViewCellCancelEventArgs e)
{
BindData();
}
private void radGridView1_CellEndEdit(object sender, GridViewCellEventArgs e)
{
try
{
var radEditor = radGridView1.ActiveEditor;
if (radEditor == null) return;
switch (radEditor.GetType().Name)
{
case "RadComboBoxEditor":
{
var element = ((RadComboBoxElement)((RadComboBoxEditor)radGridView1.ActiveEditor).EditorElement);
if (element == null) return;
var selectedText = ((RadComboBoxItem) element.SelectedItem).Text;
MessageBox.Show("Begin" + selectedText);
radGridView1.CurrentRow.Cells["column1"].CellElement.Text = selectedText;
//radGridView1.Rows[e.RowIndex + 1].Cells[e.ColumnIndex + 1].Value = element.SelectedValue;
break;
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
I can select the value from the dropdown. But the value assigned to the cell is not displaying. Please help me.
Regards
Shamjith