windows 如何从 DataGridViewComboBoxColumn 中获取 selectedvalue?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4732263/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 16:01:00  来源:igfitidea点击:

how to get selectedvalue from DataGridViewComboBoxColumn?

c#windowswinforms

提问by Nighil

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

我有一个 datagridview,它有一个 DataGridViewComboBoxColumn 作为单元我想获得每个 DataGridViewComboBoxColumn 的 selectedvalue 我怎么能得到这个?

回答by Sachin Shanbhag

You can use this -

你可以用这个——

dataGridView1.Rows["YourRowNumber"].Cells["YourColumnNameOrNumber"].Value;

回答by V4Vendetta

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

如果您正在遍历网格,那么您应该对获取组合框单元格的 FormattedValue 感兴趣,因为这将是所选组合框项目的实际持久值

dataGridView1[colIndex,rowIndx].FormattedValue

回答by Saad Saeed

dataGridView1.Rows["RowNumber"].Cells["ColumnNameOrNumber"].Valuewill return value of DataGridViewComboBoxColumnbut dataGridView1.Rows["RowNumber"].Cells["ColumnNameOrNumber"].FormattedValuewill return Displaying text of DataGridViewComboBoxColumn...

dataGridView1.Rows["RowNumber"].Cells["ColumnNameOrNumber"]。将返回 DataGridViewComboBoxColumn 的值,但 dataGridView1.Rows["RowNumber"].Cells["ColumnNameOrNumber"]。FormattedValue将返回 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

当我们的显示文本与我们设置的值不同时,它很有用... https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcell.formattedvalue(v=vs.110)。 aspx

Cheers!

干杯!