retrieving seleted value from combobox in datagridview
hello im having a problem retrieving selected value from a combobox in datagridview. my datagridview is getting its data from an sql database. so the comboboxes are filled during runtime and i dont know how to get the selected combobox item's value. all i can think of is this--
Code:
string hehe = dataGridView4.Rows[dataGridView4.SelectedCells[0].RowIndex].Cells[3].Value.ToString();
please help me get the selected item from combobox residing inside the datagridview so that i can use it in my code
Re: retrieving seleted value from combobox in datagridview
handle the CellValidated event of the gridview
inside, use the e.RowIndex to ensure it is >=0 (else you're not on a datarow)
use the e.ColumnIndex to disocver on which colum you are if you need it
to retrieve the value from the datagridviewcomboboxcolumn use:
Code:
DataGridViewComboBoxCell thisCboCell = (DataGridViewComboBoxCell)YourGridView.CurrentRow.Cells[indexOfComboBoxColumn];
if (thisCboCell .Value != null)
{
string theSelectedValue = thisCboCell.Value.ToString();
}
provided you set a ValueMember and a DisplayMember for that column, that code should give you the valuemember