how to get selectedvalue from DataGridViewComboBoxColumn?

前端 未结 3 1270
情歌与酒
情歌与酒 2021-01-24 18:54

i have a datagridview which has a DataGridViewComboBoxColumn for unit i want to get the selectedvalue of each DataGridViewComboBoxColumn how could i get this?

相关标签:
3条回答
  • 2021-01-24 19:33

    You can use this -

    dataGridView1.Rows["YourRowNumber"].Cells["YourColumnNameOrNumber"].Value;
    
    0 讨论(0)
  • 2021-01-24 19:33

    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!

    0 讨论(0)
  • 2021-01-24 19:48

    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
    
    0 讨论(0)
提交回复
热议问题