初始化自定义ComboBox(WinForms,C#)

时间:2014-03-25 20:28:06

标签: c# .net winforms combobox custom-controls

我无法在文档中找到任何正确的指导,所以我在这里问。 我有自定义组合框(继承自默认值),在运行时 - 应从远程数据源加载项(枚举)。

使用哪种方法(事件?)来初始化项目列表?我绝对不想在父容器(即Form)中这样做。

谢谢!

1 个答案:

答案 0 :(得分:0)

让我看看我是否理解你想要的东西。我假设你创建了一个UserControl。在这种情况下,您是否尝试在控件的构造函数中执行此操作?我的意思是:

public class BetterComboBox : System.Windows.Forms.ComboBox
{
    public BetterComboBox(List<SomeObject> list)
    {
         // This call is required by the Windows.Forms Form Designer.
         InitializeComponent();

         //you can pass over the list from parameter or initialize it right here.
         //if you need to call a store procedure or something, do it here.
         this.DataSource = list;
    }

    //other methods that you need to override or write
}

如果您需要处理在视图方面完成的其他事件,您还可以阅读有关处理程序的信息。希望能帮助到你! =)

相关问题