Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Instead, you can use <a href="http://msdn.microsoft.com/en-us/library/ms158145.aspx" rel="nofollow">BindingSource</a> to keep your objects synchronized.</p> <pre><code>// first binding source that points to your List of Foos BindingSource bindingSourceFoos = new BindingSource(); bindingSourceFoos.DataSource = foos; // create a second binding source that references the first's Bars property BindingSource bindingSourceBars = new BindingSource(bindingSourceFoos, "Bars"); // set DisplayMember to the property in class Foo you wish to display in your listbox fooListBox.DisplayMember = "FooName"; // my example, replace with actual name fooListBox.DataSource = bindingSourceFoos; // again, set DisplayMember to the property in Bar that you want to display in ListBox barListBox.DisplayMember = "BarInfo"; // my example, replace with actual name barListBox.DataSource = bindingSourceBars; </code></pre> <p>So, from this point on, when you click on something in the FooListBox, it will automatically change the contents of the BarListBox to that Foo's Bar collection.</p> <p>Update:</p> <p><a href="http://msdn.microsoft.com/en-us/library/ms233787.aspx" rel="nofollow">MSDN - Databinding to a user control</a></p> <p>That link should tell you everything you need to know, but just in case:</p> <p>Decorate your user control like this:</p> <pre><code>[System.ComponentModel.LookupBindingProperties ("DataSource", "DisplayMember", "ValueMember", "LookupMember")] public partial class FooSelector : UserControl, INotifyPropertyChanged </code></pre> <p>Add these members to your user control:</p> <pre><code> public object DataSource { get { return fooListBox.DataSource; } set { fooListBox.DataSource = value; } } public string DisplayMember { get { return fooListBox.DisplayMember; } set { fooListBox.DisplayMember = value; } } public string ValueMember { get { return fooListBox.ValueMember; } set { if ((value != null) &amp;&amp; (value != "")) fooListBox.ValueMember = value; } } public string LookupMember { get { if (fooListBox.SelectedValue != null) return fooListBox.SelectedValue.ToString(); else return ""; } set { if ((value != null) &amp;&amp; (value != "")) fooListBox.SelectedValue = value; } } </code></pre> <p>And then, just like in my original example, you're binding the same way as if you were binding to a normal listbox:</p> <pre><code>// fooSelector1 is your FooSelector user control fooSelector1.DisplayMember = "Name"; fooSelector1.DataSource = bindingSourceFoos; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload