【发布时间】:2014-03-25 20:28:06
【问题描述】:
我无法在文档中找到任何适当的指导,所以我在这里问。 我有自定义组合框(继承自默认值),它 - 在运行时 - 应该从远程数据源加载项目(枚举)。
使用哪种方法(事件?)来初始化项目列表?我绝对不想在父容器(即表单)中这样做。
谢谢!
【问题讨论】:
标签: c# .net winforms combobox custom-controls
我无法在文档中找到任何适当的指导,所以我在这里问。 我有自定义组合框(继承自默认值),它 - 在运行时 - 应该从远程数据源加载项目(枚举)。
使用哪种方法(事件?)来初始化项目列表?我绝对不想在父容器(即表单)中这样做。
谢谢!
【问题讨论】:
标签: c# .net winforms combobox custom-controls
让我看看我是否明白你想要什么。我假设您创建了一个 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
}
如果您需要处理在视图端完成的其他一些事件,您还可以阅读有关处理程序的信息。希望能帮助到你! =)
【讨论】: