如何访问c#datagridview组合框? [英] How to access c# datagridview combobox?

查看:71
本文介绍了如何访问c#datagridview组合框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我有datagridview哪些列是:

columncombobox,columntextbox,columntextbox,columntextbox,columncombobox,



1.我需要button1单击以从右侧组合框中获取项目文本。

2.我需要在两个组合框上更改事件处理程序。



基本上我需要在第一个改变的组合框项目上执行代码,并在右侧组合框项目上执行不同的代码更改

图片



如何做到这一点,因为它不同于经典的win形式组合框,它有一个准备好的事件更改项目。



提前感谢,我没有成功在线找到解决方案,所以我在这里问,如果你需要更多信息,请问我会回复。

(int i = 0; i< = dgList.Rows.Count - 1; i ++)
{
DataGridViewComboBoxCell cell = dgList.Rows [i] .Cells [0] as DataGridViewComboBoxCell;
string strVal = cell.Value.ToString();
string strtext = cell.OwningColumn.HeaderText();
}

//Cell.OwningColumn公开拥有所选单元格的列。


//此代码给出了拥有列的标题。

OR

//如果我说你想要格式化的值(文本)和所选的值(值)那么//在这种情况下试试这个:

for(int i = 0; i< = dgList.Rows.Count - 1; i ++)
{
DataGridViewComboBoxCell cell = dgList.Rows [i] .Cells [0] as DataGridViewComboBoxCell ;
string strVal = cell.Value.ToString();
string strtext = cell.FormattedValue.ToString();
}


basically i have datagridview which columns are:
columncombobox, columntextbox, columntextbox, columntextbox, columncombobox,

1. i need on button1 clicked to get the item text from the right combobox.
2. i need to make event handlers on both combobox changed.

basically i need to execute code on the first combobox item changed and different code to be executed on the right combobox item change
picture

how to do this, since its different than the classic win forms combobox, there it has a prepared event on item changed.

thanks in advance, i didnt successed in finding the solution online so i asked here, if u need more info, ask and i will reply.

解决方案

for (int i = 0; i <= dgList.Rows.Count - 1; i++) 
            { 
                DataGridViewComboBoxCell cell = dgList.Rows[i].Cells[0] as DataGridViewComboBoxCell; 
                string strVal = cell.Value.ToString();
                string strtext = cell.OwningColumn.HeaderText();
            }

//Cell.OwningColumn exposes the column that owns the selected cell.
 

//This code gives the heading of the owning column.

OR

//If I say you want the formatted value (text) and the selected value (value) then //in that case try this :

 for (int i = 0; i <= dgList.Rows.Count - 1; i++) 
            { 
                DataGridViewComboBoxCell cell = dgList.Rows[i].Cells[0] as DataGridViewComboBoxCell; 
                string strVal = cell.Value.ToString();
                string strtext = cell.FormattedValue.ToString();
            }


这篇关于如何访问c#datagridview组合框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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