, :
, , , gridview, unbound comboboxColumn, , , datagridview , , CellEndEdit RowStateChanged:
DataGridViewComboBoxColumn col = new DataGridViewComboBoxColumn();
col.DataSource = Enum.GetValues(typeof(MyEnum));
col.Name = "testcolumn";
int index = dataGridView1.Columns.Add(col);
//"index" is if you want to set properties and so on to this column
//but no need for this example.
//dataGridView1.Columns[index].Name = "testcolumn";
dataGridView1.DataSource = test;
//the 2 event-handlers
dataGridView1.CellEndEdit += new DataGridViewCellEventHandler(dataGridView1_CellEndEdit);
dataGridView1.RowStateChanged += new DataGridViewRowStateChangedEventHandler(dataGridView1_RowStateChanged);
(CellEndEdit , , , , comboboxcell);
void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == dataGridView1.Columns["TestCol"].Index)
{
dataGridView1.Rows[e.RowIndex].Cells["testcolumn"].Value = (MyEnum)((int)dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value);
}
}
private void dataGridView1_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e)
{
if (e.Row.DataBoundItem != null)
{
e.Row.Cells["testcolumn"].Value = (MyEnum)((int)e.Row.Cells["TestCol"].Value);
}
}
, , 0 2 5, , , 5 , , :
public enum MyEnum
{
zero,
one,
two,
three,
four,
five
}