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
Hello,
You could try setting the 'NodeStyle' property of the nodes to 'CheckBox'. Please take a look at the following link:
http://help.infragistics.com/NetAdvantage/WinForms/2012.2/CLR4.0/?page=Infragistics4.Win.UltraWinTree.v12.2~Infragistics.Win.UltraWinTree.Override~NodeStyle.html.
Please feel free to let me know if I misunderstood you or if you have any other questions.
Hi Boris,
I tried your suggestion (and TriStateCheckBox) with no success. Which I'm not surprised at as the NodeStyle property is not applicable when the ViewStyle is something other than Standard (I have it set to OutlookExpress)
I've updated the sample project to be more like what I need/have (the inclusion of a 'combobox' style control but I have no issues with that). I've added more checkbox columns so there is one for each AllowCellEdit setting (just saves me a lot of stopping, altering the setting and rerunning when trying the permutations). I've also changed the check box columns data type to be objects instead of booleans as these were causing me casting errors elsewhere.
At present the only real differences between this and what I want/have is that most of the setup up is done at design time in what I have, and I've also added code to handle the check box state of child nodes when setting a parent node, and for updating the parent check box state when setting a child node.
Also, I assume I have set it wrong, but I can't seem to get the Name column to auto resize based on the contents.
NodeStyle will not have any effect here because you are using column and NodeStyle only works on standard nodes.
Anyway... to make the checkbox cell editable, you have to set AllowCellEdit. Presumably, you would set this on the column(s) that you want to be editable. But if you want all columns to be editable, you could set it on the ColumnSet instead of on each column.
Also, you need to set CellClickAction to EditCell.
this.ultraTree.Override.CellClickAction = CellClickAction.EditCell;
To trap when the checkbox is changed, use the CellValueChanged event.
To autosize a column to it's contents, you can call:
column.PerformAutoResize(ColumnAutoSizeMode.AllNodesWithDescendants);
Be sure to do this AFTER you populate the column with data, of course. :)
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.
Yip that's fixed it thanks Mike.
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.
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
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.