i have added a datagridviewcomboboxcolumn like this:
DataGridViewComboBoxColumn colCategory = new DataGridViewComboBoxColumn();
colCategory.Name = "CATEGORY";
colCategory.DataPropertyName = "CATEGORY";
colCategory.HeaderText = "CATEGORY";
colCategory.SortMode = DataGridViewColumnSortMode.Automatic;
colCategory.Items.AddRange(new string[] { "Subsystem", "Library", "Unknown", "Hole" });
this.dgBuildFile.Columns.Insert(1, colCategory);
this combobox is not bound to any datasource.
when i select any item from the list and go to next cell, the value is not displayed in the cell. how can i achieve it?
Satish KathiPosted Dec 10, 2008, 11:51 AM
Your code is working fine
And I am able to select the values from the ComboBox and the values are displaying in comboBox
Even when you are moving on to next cell the combo box is displaying the selected value
Do you want selected item in the combo box to be displayed in next cell
If so
Implement the following in dataGridviewCellValidated event
private void dgBuildFile_CellValidated(object sender, DataGridViewCellEventArgs e)
{
//Column index of the combo box column is 1
if (e.ColumnIndex == 1)
{
//Set the value of the column 3 to the selected value of the combo box
dgBuildFile.Rows[e.RowIndex].Cells[2].Value = dgBuildFile.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
}
}