Dear all,
perhaps I am being stupid but it seems rather difficult to display a simple UltraTree with some columns set to checkboxes. As an aside I find the Infragistics documentation very poor on all sorts of things, to the point I now no longer use it and try google instead.
But back to my main point, as a first step I tried getting an UltraTree with columns. I've tried all the advice of different dispaly styles, etc. with no luck. I've attached a simple project showing my point. I've created a form with an UltraTree which has 3 columns at design time, one should be a string with the other two booleans (for the check boxes). This is then populated with nodes but I can not get the columns to appear.
There is no binding to a datasource as I intend to extend this once I have the basics working, and for instance the parent nodes will have check boxes which set all the child nodes, but really in the datasource only the child nodes exist (so, as I understand it, binding wouldn't work).
I do not want grids within nodes, like the examples show, besides for me personally thinking it looks ugly and information overload, I do not require it as all the nodes will have the same columns so I only need one set of headers at the very top.
Where am I going wrong?
Regards,
Hi,
The tree is a bit more complex than some other controls because the ColumnSets are abstracted from the nodes. This allows you to assign different columns to each level, or even to each individual node, but it makes doing simple things a little bit tougher.
You appear to have created three ColumnSets at design-time in your tree, but there are two problems here, I think.
First, judging by the names you used, the fact that there are three of them, and the fact that none of your ColumnSets have any columns in them I think you are expecting a ColumnSet to be a Column. A ColumnSet is a set of columns, so you only need a single ColumnSet here with 3 columns in it.
The other problem is that you haven't hooked up any of the ColumnSets to any nodes.
Another issue, unrelated to ColumnSets is that the code in your sample is adding nodes with duplicate keys. Keys in the tree have to be unique across the entire tree, not just in the same collection. You are adding in the parent node's text, but your parent nodes have no text in this case because you never assigned any.
I have modified your sample with an UltraCheckEditor, and I fixed the duplicate key issue by using the Key of the parent node instead of the Text. And I wrote code to set up and apply the ColumnSet correctly. Note that you could get your nodes to return Text if you assign a value to the first string column in the node (the Name cell) and then you could use Text instead of Key.
Thanks for that Mike. I worked out the ColumnSet columns difference later in the day (I did want want one ColumnSet with three columns) and fixed the Text/Key issue as well.
However, where your solution has been really useful is using UltraCheckEditors. I had been simply making the column datatype boolean and AllowCellEdit to be Full which gave the appearance of and allowed me to edit checkboxes. But I ran into difficulty when I went to set the parent node to intermediate, basically I was getting ArgumentTypeExceptions and NullReferenceExceptions as I was trying to cast between booleans and CheckState. So now I have set the EditorComponent to be an ultraCheckEditor and the DataType to be object, which allows such casting without exceptions.
A quick follow up if I may. How do I enabling editing of the UltraCheckBox? I've tried all sorts of combinations of settings for the UltraTree.Override.CellClickAction and the Columns AllowCellEdit. And what event get's fired when I change the value? CellValueChanged, the editor's CheckedChanged or CheckedValueChanged events.
Regards
Hi Mike,
I was doing the resize before adding the contents :(
If you look at the latest example in my last post, you'll see I have CellClickAction set to EditCell and I have columns for all the AllowCellEdit settings, but none of them allow me to edit the checkbox value/state.
The ComboBox column in your sample is working just fine. I can drop down the list and update it.
The "Full" column isn't working because the DataType of the column is object and the UltraCheckEditor doesn't know what to do with an object, it needs a better data type like bool.
Thanks for that Mike.
However, I set the underlying DataType to be objects and not booleans to prevent a casting issue. This is demonstrated in the attached example. Basically the same project but with just the CheckBox column, however when un/checking a checkbox any children if present are set to the same value and any parents are updated to reflect the values of their children.
Setting the children is fine. However, trying to set the parent to an indeterminate state can not be done as it is a boolean and must therefore be true or false.
To reproduce:
1 - Run the attached project
2 - Expand the A and A1 node
3 - Uncheck the A1 checkbox, all the A1 children correctly become unchecked
4 - Check one of the A1 children. It now doesn't know how to set the A1 node. It should be indeterminate but the DataType is boolean which has no equivalent
It doesn't have to be an object to support indeterminate state. For Indeterminate, you use DBNull.Value. This is, in fact, the initial state in the sample.
Yip that's fixed it thanks Mike.