Hi Aarron345,
Usually, we use DataGridViewComBoxCell to populate other fields of DataGridView, such as auto fill fields of other columns.
However, sometimes, we’d like to make it act more like a real ComBox which can display item directly, right.
Then I’d like to suggest you using DataGridView.EditingControlShowing event, in which you can change ComboBoxCell into ComboBox and set its SelectedItem. Please refer to the following code:
Code Snippet
private void dataGridView2_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if (this.dataGridView2.CurrentCellAddress.X == 0)
{
ComboBox c = e.Control as ComboBox;
c.SelectedItem = c.Items[0];
}
}
Furthermore, because I cannot be sure about how you get “ID�and how you use it to find the match item, I’d like to provide some information about DisplayMember and ValueMember of ComboBoxCell.
We usually use ValueMember to implicitly indicate what value will be displayed for user. Note that ValueMember cannot be seen directly, we can only see its corresponding DisplayMember through UI. So, under this problem, we can set ValueMember to “ID�and set DisplayMember to corresponding field like “name�
For more information about DisplayMember, ValueMember and Value properties, please refer to the following pages:
DataGridViewComboBoxCell.ValueMember Property
DataGridViewComboBoxCell.DisplayMember Property
Please do not hesitate to let me know if there is still question.
Thanks.
Best wishes,
Jun Wang