在获胜表格中设置组合框项目的值 [英] setting value of combobox item in win forms

查看:80
本文介绍了在获胜表格中设置组合框项目的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何设置组合框项目的值.

我想设置组合框项目的文本和值.


这样,当我获得selecteditem时,我就可以轻松获得该项目的价值.
但是在显示时我会显示文本.

我尝试制作组合框的对象,但是它显示空白并带有消息框.

How can set the value of a combobox item.

i want to set the text and value of a combobox item.


so that when i get the selecteditem .i can easily get the value of the item.
But while displaying i display text.

I tried making an object of combobox but it shows blank with a messagebox

推荐答案

请参见 ^ ]方法和属性.
See the http://msdn.microsoft.com/en-us/library/system.windows.forms.combobox.objectcollection.add.aspx[^] methods and properties.


我认为这与发布的解决方案几乎是相同的问题:http://stackoverflow.com/questions/2023316/c-sharp-winforms-combobox-with-label-and-value [ ^ ]

cbo是您的ComboBox,myData包含以下值:
I think this is pretty much the same question together with a solution posted: http://stackoverflow.com/questions/2023316/c-sharp-winforms-combobox-with-label-and-value[^]

cbo is your ComboBox, myData contains the values:
var data = myData.Select(oneData => new {
     Value = oneData.Value, Text = oneData.Name}).ToList();
cbo.ValueMember = "Value";
cbo.DisplayMember = "Text";
cbo.DataSource = data;


组合框 [ ^ ]具有许多属性要实现以下目标:
- SelectedIndex [ SelectedItem [ SelectedText [
ComboBox[^] has many properties to achieve that:
- SelectedIndex[^]
- SelectedItem[^]
- SelectedText[^]


这篇关于在获胜表格中设置组合框项目的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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