您的位置:首页 > 其它

如何获取绑定数据的combobox的选中值及选中text

2012-03-28 16:30 609 查看
1、绑定combobox的代码如下:

DataTable LDT_CodeType = Models.MoCodefile.GetCodeType();

if (LDT_CodeType != null)

{

cboxCtype.DataSource = LDT_CodeType;

cboxCtype.DisplayMember = "codetypename";

cboxCtype.ValueMember = "codetypeno";

}

获取选中值:cboxCtype.SelectedIndex.ToString() 或是 cboxCtype.SelectedValue.ToString()

获取选中text:

方法一:DataRowView dr = (DataRowView)cboxCtype.Items[cboxCtype.SelectedIndex];

方法二:cboxCtype.GetItemText(cboxCtype.Items[cboxCtype.SelectedIndex])

2、C#中ComboBox能否设定多个ValueMenber?

举个例子:表student,有字段id,name,tel有个combobox绑定了这个表,其中DisplayMember设置为id,现要取出对应的name和tel, 用ValueMember只能取一个,该怎么做呀?

一般是这样绑定和取值: comboBox1.DataSource = student; //绑定student表为数据源comboBox1.DisplayMember = "name"; comboBox1.ValueMember = "id"; string name = comboBox1.SelectedText;//取DisplayMember值 string id = comboBox1.SelectedValue.ToString();//取ValueMember值 DataTable table1
= this.comboBox1.DataSource as DataTable; int rowIndex = this.comboBox1.SelectedIndex; string str1 = table1.Rows[rowIndex]["tel"].ToString();//取绑定表中的其它值

3、C# Winform ComboBox 在输入内容时 会在下拉菜单中显示 根据输入内容查询的结果

http://zhidao.baidu.com/question/180144652.html

4、

winform中设置combobox的只能选择不能输入

设置combobox的属性面板中的

属性:“DropDownStyle”为“DropDownList”
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐