Solved

Binding to class collection, with class having collection property

Posted on 2004-04-09
5
617 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now