如何获取Datagridview Combobox的TEXT选项?

pal*_*aѕн 8 c# combobox datagridview selectedtext winforms

如何获取DataGridView中的Combobox选定项目文本?我尝试使用以下代码:

dataGridView1.Rows[1].Cells[1].Value.ToString()
Run Code Online (Sandbox Code Playgroud)

但是,这会给出与此单元格关联的值,而不是Combobox选定的项目文本.我也试过这个:

DataGridViewComboBoxCell cell = dataGridView1[1,1] as DataGridViewComboBoxCell;
string value = cell.Value.ToString();
Run Code Online (Sandbox Code Playgroud)

但是,这也没有帮助.

我很感激你的帮助.提前致谢!

编辑:

比方说,我们有一个Combobox文本为NoYes,值分别为0和1.我想要得到的是文本,Yes或者No当Combobox被更改时.但我得到的是使用上述代码的值0/1.希望能让事情变得清晰.

更新:

好的,所以我一直在研究这个问题,经过很多努力并在其他成员的帮助下,我已经能够解决问题并获得所需的解决方案:

这是解决方案:

string SelectedText = Convert.ToString(dataGridView1.Rows[0].Cells[1].FormattedValue.ToString());
Run Code Online (Sandbox Code Playgroud)

Rah*_*put 15

要在DataGridView中获取Combobox的选定值和所选文本,请尝试以下代码

string SelectedText = Convert.ToString((DataGridView1.Rows[0].Cells["dgcombocell"] as DataGridViewComboBoxCell).FormattedValue.ToString());
int SelectedVal = Convert.ToInt32(DataGridView1.Rows[0].Cells["dgcombocell"].Value);
Run Code Online (Sandbox Code Playgroud)