Binding to class collection, with class having collection property
Posted on 2004-04-09
I have a class "Strategy" that contains properties, one of which is itself a collection of elements related to the Strategy class (just like in a typical master-detail relationship). Here are some of
public class Strategy:IComparable, ICloneable
private int m_ID;
private string m_Name;
private string m_SectorCode;
private ArrayList m_AssetClasses;
I have created a collection of Strategy classes and would like to bind this to a VB.NET form so that:
(a) A Listbox Control displays the Name of each Strategy class instance within the "parent" collection (the m_Name property above).
(b) A data record group area within the form displays the properties of the selected strategy class instance, including all the items contained in the "child" collection (the m_AssetClasses collection). Each such item is a simple text value, so a Listbox will suffice).
I found out that it's very easy to bind the strategy (parent) collection to a Listbox:
' Here "strategies" is the parent collection array
Me.lbListing.DataSource = strategies
Me.lbListing.DisplayMember = "Name"
Me.lbListing.ValueMember = "ID"
Me.txtID.DataBindings.Add("Text", strategies, "ID")
Me.txtName.DataBindings.Add("Text", strategies, "Name")
currencyManager = Me.BindingContext(strategies)
currencyManager.Position = 0
But I am not sure how to bind the "child" collection to its own Listbox within the context of the parent class binding.
I looked around quite a bit, but have not yet found any real helpful information or similar example.
Any advice or suggestion will be very much appreciated.