在Windows窗体应用程序中编辑组合框 [英] Edit combobox in windows form application

查看:68
本文介绍了在Windows窗体应用程序中编辑组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我是

绑定组合框使用以下代码

组合框绑定代码

Hi I am
binding combo box Using following code
combobox binding code

cProduct obj = new cProduct();
            obj.ppro_CompanyId = csession.CompanyId;
            obj.ppro_IsActive = "true";
            cmbProduct.DisplayMember = "ppro_ProductName";
            cmbProduct.ValueMember ="ppro_ProductId";
            cmbProduct.DataSource = obj.GetProduct();//returns Array list



现在想以编程方式选择组合框到指定的ValueMember



请帮帮我


Now Want to programatically select the combobox to a specified ValueMember

Please help me

推荐答案

在进行数据绑定后,您可以为组合框设置 SelectedIndex 属性。



更新:这只是工作。



You can set SelectedIndex property for the combobox after doing data binding.

Update: This just works.

List<MyClass> lst = new List<MyClass>();
           lst.Add(new MyClass { MyProperty = 1, MyProperty1 = "1" });
           lst.Add(new MyClass { MyProperty = 2, MyProperty1 = "2" });
           lst.Add(new MyClass { MyProperty = 3, MyProperty1 = "3" });

           comboBox1.DataSource = lst;
           comboBox1.DisplayMember = "MyProperty1";
           comboBox1.ValueMember = "MyProperty";

           comboBox1.SelectedValue = 2;


这篇关于在Windows窗体应用程序中编辑组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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