?
Solved

Binding to class collection, with class having collection property

Posted on 2004-04-09
5
Medium Priority
?
624 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

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)…
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

752 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