在最后决定提出这个问题之前,我进行了广泛的搜索。我跟踪了MSDN关于创建用户控制工具的教学,该工具使用简单、复杂和查找数据。
- Walkthrough: Creating a User Control that Supports Simple Data Binding
- Walkthrough: Creating a User Control that Supports Complex Data Binding
- Walkthrough: Creating a User Control that Supports Lookup Data Binding
并且它们运作得很好... 对于一个用户控制器,它只使用 单一的组合盒或网景。
现在我要创建一个用户控制器, 有三个不同的组合框。 我要将每个组合框绑在不同的表格上。 这些表格是名称、 类型和产品 。
MSDN 教程涉及为单一的 Combox 创建 DataBindingProperty, 但是没有显示如何对包含多个一个的用户控制进行同样的操作 。
using System.Windows.Forms;
namespace CS
{
[System.ComponentModel.LookupBindingProperties(
"DataSource", "DisplayMember", "ValueMember", "LookupMember")]
public partial class LookupBox : UserControl
{
public object DataSource
{
get{ return comboBox1.DataSource; }
set{ comboBox1.DataSource = value; }
}
public string DisplayMember
{
get{ return comboBox1.DisplayMember; }
set{ comboBox1.DisplayMember = value; }
}
public string ValueMember
{
get{ return comboBox1.ValueMember; }
set{ comboBox1.ValueMember = value; }
}
public string LookupMember
{
get{ return comboBox1.SelectedValue.ToString(); }
set{ comboBox1.SelectedValue = value; }
}
public LookupBox()
{
InitializeComponent();
}
}
}
现在,如你所见,代码中只提到一个组合框。 我需要三个组合盒, 每个组合盒都绑在上面提到的不同的表格上。
我的头撞墙。我不太擅长用户控制(尽管我在 ASP.NET 中使用过),但似乎还是个好主意,因为我在应用程序的不同地方 将这三个组合箱放在一起使用。