suppose i have one datagridview and datagridview has one DataGridViewComboBoxColumn.
i have populate datagridview combobox column with country name and code.
so now i want that when i am reading datagridview cell value in for loop then i want get DataGridViewComboBoxColumn selected value and text. i could not get the value but not being able to get display text from DataGridViewComboBoxColumn in for loop.
if it is possible then plzz help me with small code.
private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i <= dgList.Rows.Count - 1; i++)
{
DataGridViewComboBoxCell cell = dgList.Rows[i].Cells[0] as DataGridViewComboBoxCell;
int index = cell == null || cell.Value == null ? -1 : cell.Items.IndexOf(cell.Value);
string strVal = cell.Value.ToString();
}
}
thanks
Can you try accessing the values like
FormattedValueandValue, this should give you the two values.I had tried using a
Dictionary<string,string>asDataSourceand using the above properties i was able to get both the values.