anna john

anna john

  • NA
  • 47
  • 9k

how to retrieve datagridview combobox columns selected value

Oct 29 2019 3:40 PM
i would like to know what is the selected value of a combobox column in the datagrid view.
for example, i have a combobox called category in my datagrid view. and if the category has values filled up a table in access. and i want to display it in messagebox once its selected/updated.
i am not sure what events should i use .. i tried something like this .. but its not working
 
private void dgv1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
combo = e.Control as ComboBox;
if (combo != null)
{
combo.SelectedIndexChanged -= new EventHandler(combo_SelectedIndexChanged);
combo.SelectedIndexChanged += combo_SelectedIndexChanged;
}
}
private void combo_SelectedIndexChanged(object sender, EventArgs e)
{
string selected = (sender as ComboBox).SelectedItem.ToString();
MessageBox.Show(selected);
}
 

Answers (1)