Hello,
I'm setting up an UltraTree bound to a binding source. This binding source is itself bound to an object which contains several generic collections.
What I would like to do is add a root node and customize the label for the nodes corresponding to the collections of my object.
Can anyone help me?
Thanks,
Damien
OK. Thanks for the input Mike!
Hi Damien,
If your primary concern is efficiency, then I thikn you are probably right. In my experience DataBinding is not intended to be the most efficient way to do things. The advantage of data binding is convenience - it's generally quicker and easier to set up.
You could load the try manually in code and it would probably be more efficient - especially if you are just displaying read-only data to the users.
Mike,
I guess I could expose a dictionary in my Configuration class, something like a Dictionary<string, Collection<BaseClass>> where BaseClass is a base class for InputStructure, Reference, Processing. I already have such a base class so that shouldn't be a problem.
But I'm not sure that DataBinding with objects is that efficient in WinForms. For instance, if I modify the Name property in an InputStructure and my UltraTree ViewStyle is set to standard, I have to call ResetBindings on the BindingSource for the label of the corresponding node in the tree view to be updated (although the tool tip has been updated "live").
To be honest, I have never really used DataBinding until I started playing with WPF. Now that I start a new application with WinForms I thought I should give it a try... Do you have an opinion on that?
I beleive you are correct.
If you want your data source (the Configuration class) to be able to support returning multiple tables, I think you would have to have it implement IListSource.
Hi Mike,
Thanks for your answer.
After some tests (and if I understand this correctly), I managed to use your solution: I need to add a root node and as many child nodes to this node as I have collections in my object because I can only bind to the collections and not to my object! That means I cannot use my binding source anymore...
Let me concretise this a little bit. I have a Configuration objet with several generic collection properties (InputStructures, Processings and References). What I want to have in my tree view is this:
Configuration - Input structures - Input structure 1 - Input structure 2 - Processings - Processing 1 ...
Since I am trying to use databinding as efficiently as possible, I have set up a BindingSource in my UserControl that I use as the datasource for several controls, including my UltraTree. The DataSource property of this BindingSource is of course an instance of my Configuration class. But maybe I am doing something wrong...
I have added a zip file containing a downsize version of my project. I have added your solution (at least the way I understood it and had it work).
So, is that the only way? Is there a way I can use my BindingSource object?