如何获得DataGridView的ComboBox中选定项的文本? [英] How to get the TEXT of Datagridview Combobox selected item?

查看:171
本文介绍了如何获得DataGridView的ComboBox中选定项的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获得组合框中选定项的文本这是一个DataGridView里面呢?
我已经尝试使用下面的代码尝试:

  dataGridView1.Rows [1] .Cells [1] .value的。的ToString()

不过,这给这个细胞,不ComboBox中选定项文本关联的值。
我也试过这样的:

 的DataGridViewComboBoxCell电池= dataGridView1 [1,1]作为的DataGridViewComboBoxCell; 
字符串值= cell.Value.ToString();



不过,这也没有帮助。



我会感谢你的帮助。 !在此先感谢



编辑:



让我们说,我们有一个组合框文本为和值分别为0和1。我想,这里的文字,当组合框被改变。但我得到是利用上述码值0/1。希望使事情变得清楚了。



更新:



好了,我一直在这个问题上大量的努力,并与我的同胞成员的帮助后,我已经能够解决这个问题,并获得所需的解决方案:



下面是解决方案:

 字符串SelectedText = Convert.ToString(dataGridView1.Rows [0] .Cells [1] .FormattedValue.ToString()); 


解决方案

要获得选择的值,并在DataGridView中选定的组合框的文本试试下面的代码

 字符串SelectedText = Convert.ToString((DataGridView1.Rows [0] .Cells [dgcombocell]作为的DataGridViewComboBoxCell ).FormattedValue.ToString()); 
INT SelectedVal = Convert.ToInt32(DataGridView1.Rows [0] .Cells [dgcombocell]值。);


How to get the Combobox selected item text which is inside a DataGridView? I have tried using the below code:

dataGridView1.Rows[1].Cells[1].Value.ToString()

But, this gives the value associated with this cell, not the Combobox selected item text. I also tried this:

DataGridViewComboBoxCell cell = dataGridView1[1,1] as DataGridViewComboBoxCell;
string value = cell.Value.ToString();

But, this also didn't help.

I would appreciate your help. Thanks in advance!

EDIT:

Let's say, we have a Combobox with text as No and Yes and the values as 0 and 1 respectively. What I want to get here's the text Yes or No, when the Combobox is changed. But what I am getting is the values 0/1 using the above codes. Hope that makes things clear.

UPDATE:

Ok, so I have been working on this issue and after lots of efforts and with help from my fellow members, I have been able to resolve the issue and get the required solution:

Here's the solution:

string SelectedText = Convert.ToString(dataGridView1.Rows[0].Cells[1].FormattedValue.ToString());

解决方案

To get selected value and selected text of Combobox in DataGridView try following Code

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

这篇关于如何获得DataGridView的ComboBox中选定项的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆