Solved

Binding to class collection, with class having collection property

Posted on 2004-04-09
5
619 Views
Last Modified: 2007-12-19
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
the properties:

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.

Best,
Stefano
0
Comment
Question by:sdamiano
  • 2
5 Comments
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 10794652
when the selection change occurs on the parent trap the event and rebind the second listbox to child array in the of the parent.
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 10794654
oops bad english trap the event and rebind the child list to the currently selected item. I believe you can actually do this purely through databinding though ...
0
 

Author Comment

by:sdamiano
ID: 10799276
Hello Greg,

thanks for the answer, what you suggest is in fact what I am doing, but my question was to see if there is way this can be done automatically - maybe that wasn't too clear in my description. The fact is that if I have a hierarchical collection of objetcs with many levels (my example was a simple one, with one level), and I really don't want to manage that myself...  

What I found out is the following:

- If one creates a collection that implements the Ibindable interface, then it looks like this may work. However this is not ideal, nor particularly easy, and it requires too much coding for my own taste and time constraints.

- There are some UI toolboxes that are a lot better than those that come with .NET. The best seems to be by Infragistics, I downloaded the trial version and so far I am impressed. It integrates perfectly within .NET and their grid control does hierarchical binding automatically to any collection, which is the way I like it! So I am going to buy this (it's only $500-1,000 per developer depending on the package).

Best,
Stefano
0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
ID: 10799384
User resolved; closed, 500 points refunded.
Netminder
Site Admin
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question