Solved

Binding to class collection, with class having collection property

Posted on 2004-04-09
5
622 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

729 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