Solved

Binding to class collection, with class having collection property

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

867 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

21 Experts available now in Live!

Get 1:1 Help Now