如何在c#.net中为组合框设置默认值? [英] How to set a default value for a Combo Box in c#.net?

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

问题描述

如何在c#.net中为组合框设置默认值?

我想在datasourse包含公司名称后绑定第一个"--- select ---"

喜欢

--selct--
印度
什里兰卡
美国
加拿大


在此先感谢

How to set a default value for a Combo Box in c#.net?

i want to bind first "---select---" after datasourse contains comapny name

like

--selct--
india
shrilanka
USA
Canada


thanks in advance

推荐答案

将此"--- Select ---"作为数据源集合中的一项插入,并将组合框的选定索引属性设置为相应的索引
Insert this "---Select---" as an item in the data source collection and set selected index property of combobox to the corresponding index of that object.


Amit,您可能要将值从数据库绑定到组合框,然后可能需要在顶部插入"--Select--".为此,您可以使用下面给出的代码,


comboBox1.Items.Insert(0,new ListItem(-Select-","0"));


这将满足您的需要.

阿努拉格
@cheers @
Amit, you may be binding your values to the combobox from the database and then you may need to insert "--Select--" at the top. For this you can use the code given below,


comboBox1.Items.Insert(0, new ListItem("--Select--","0"));


This will do the bit you need.

Anurag
@cheers@


您可以通过
在组合框中插入数据
< pre lang ="cs">私有无效Form1_Load(对象发送者,EventArgs e)
{
comboBox1.Items.Add(select);
< pre lang ="sql"> comboBox1.Items.Add(jaipur);</pre>

}</pre>
you can insert data in combobox by

<pre lang="cs">private void Form1_Load(object sender, EventArgs e)
{
comboBox1.Items.Add(select);
<pre lang="sql">comboBox1.Items.Add(jaipur);</pre>

}</pre>


这篇关于如何在c#.net中为组合框设置默认值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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