I’ve done some extensive searching before finally deciding to ask this question. I’ve followed the MSDN tutorials on creating User Controls that use Simple, Complex and Lookup Data Binding.
- 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
And they work great…for a User Control that only uses a single Combobox or Gridview.
Now I want to create a User Control with three different Comboboxes. I want to bind each one to a different Table. The tables are ‘Names’, ‘Types’, and ‘Products’.
The MSDN tutorials involve creating DataBindingProperties for a single Combobox, but do not show how to do the same for a user control that contains more than one.
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();
}
}
}
Now, as you can see, there is only one Combobox mentioned in the code. I need to have three Comboboxes, each bound to a different table as mentioned above.
Please, I’m banging my head against the wall. I’m not too well versed in User Controls (although I have used them in ASP.NET), but it seems like a good idea make one since I’m going to be using these three Comboboxes together quite a lot in different places in my application.
I would create a
UserControlthat contained three of yourLookupBox‘s. For example: