i have a datagridview which has a DataGridViewComboBoxColumn for unit i want to get the selectedvalue of each DataGridViewComboBoxColumn how could i get this?
You can use this -
dataGridView1.Rows["YourRowNumber"].Cells["YourColumnNameOrNumber"].Value;
-
by using this i am getting the text here not the value. i want to get the value instead i used this now it is working fine dataGridView1.Rows["YourRowNumber"].Cells["YourColumnNameOrNumber"].Value – Nighil Jan 19 '11 at 6:28
-
@NIGHIL DAS - So it is working fine now right? Have edited my answer to reflect correct answer. – Sachin Shanbhag Jan 19 '11 at 6:34
If you are looping through the grid then you should be interested in getting the FormattedValue of the Combobox cell since that would be actual persisted value of the selected combobox item
dataGridView1[colIndex,rowIndx].FormattedValue
dataGridView1.Rows["RowNumber"].Cells["ColumnNameOrNumber"].Value will return value of DataGridViewComboBoxColumn but dataGridView1.Rows["RowNumber"].Cells["ColumnNameOrNumber"].FormattedValue will return Displaying text of DataGridViewComboBoxColumn ...
It is useful when our displaying text is different from value we are setting ... https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcell.formattedvalue(v=vs.110).aspx
Cheers!