C#.net中组合框的默认值 [英] Default value for combobox in C#.net

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

问题描述



如何在组合框中设置默认值。



问候

Balamurugan

Hi,
How to set a default value in combobox.

Regards
Balamurugan

推荐答案

要设置所选的默认项,只需使用(例如):

To set the default item that is selected, just use (for example):
myComboBox.SelectedIndex = 5;        // set the 6th item in list as selected


public void FillCmbo(String Sql, ComboBox cmb, String name, String id)
       {
           try
           {
               if (Con.State == ConnectionState.Open)
                   Con.Close();
               Con.Open();

               OleDbDataAdapter Ada = new OleDbDataAdapter(Sql, Con);
               DataTable Dte = new DataTable();
               Ada.Fill(Dte);
               DataRow Drw;
               Drw = Dte.NewRow();
               Drw.ItemArray = new object[] { 0, "<----Select---->" };
               Dte.Rows.InsertAt(Drw, 0);
               cmb.DisplayMember =name;
               cmb.ValueMember = id;
               cmb.DataSource = Dte;
           }
           catch (System.Exception ex)
           {

               MessageBox.Show(ex.Message, "Check", MessageBoxButtons.OK, MessageBoxIcon.Information);
           }
       }





/ ............ ....你也可以使用

ComboBox.selectIndex = 0;



/................you can also use
ComboBox.selectIndex=0;


请参考这些链接:

1) http://social.msdn.microsoft.com/forums / en-US / winforms / thread / 1bbfc2b0-f099-4572-be70-e70a27ec2eed / [ ^ ]

2) http://stackoverflow.com/questions/7309164/setting-combobox-default-value-using-selectedindex [<一个href =http://stackoverflow.com/questions/7309164/setting-combobox-default-value-using-selectedindex\"target =_ blanktitle =New Window> ^ ]
Please refer these links:
1) http://social.msdn.microsoft.com/forums/en-US/winforms/thread/1bbfc2b0-f099-4572-be70-e70a27ec2eed/[^]
2) http://stackoverflow.com/questions/7309164/setting-combobox-default-value-using-selectedindex[^]


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

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