I've got a custom list that I'm binding to the tree, which works fine. I don't want checkboxes throughout every level of the tree, I just want checkboxes on the nodes at the LAST level (last descendant).
At the moment, I'm able to handle the InitializeDataNode event, and see the nodes being initialized. When a node's ListObject happens to be of a specific type (my custom type), I set the Override property of that node, like this:
private void ultraTree1_InitializeDataNode(object sender, Infragistics.Win.UltraWinTree.InitializeDataNodeEventArgs e) { if (e.Node.ListObject is MyObject) { e.Node.Override = _over; } }
The _over object is just a class-level Override, which looks like this:
_over.NodeStyle = NodeStyle.CheckBox;
PROBLEM IS.... even though I can see the Override property being set, the checkbox never shows up in my tree. Any ideas?
Thanks guys!
Hi,
If you are binding the tree to a data source, then the tree is probably displaying in a grid style with columns. The CheckBox setting you are using here only applies to standard nodes, it does not apply to nodes that are in a grid style.
If you want a checkbox in a grid-style node, you will need to put the checkbox into a column. So what you probably need to do here is an an unbound column to the ColumnSet that is being used by your lowest-level nodes.
So, assuming you are not creating the column sets yourself and that you are just letting the tree generate them automatically, then what you should do is handle the ColumnSetGenerated event and check the Key of the ColumnSet to find the right one for the band of data at the lowest level. The you can add a column to that ColumnSet and set it's DataType to boolean to make it a checkbox.
Hey, thanks Mike. Very well explained. You brought up a related point, which I'll address using the following dummy data structure:
[Root - not displayed] Company Employee Car Company Employee Car Car Car
Turns out, it'd be nice if I could display the Company and Employee levels as "standard" nodes (and maybe some custom icons?), and allow the user the see only the Car information in a grid format, and allow individual Car rows to be selected via a checkbox. Is it possible?
The more I think about it, do you think it would make more sense to do this whole thing with an UltraGrid control?
Thanks again, Don
The grid cannot have "standard" nodes, so if that's what you want, I would stick with the tree.
You can do all of this with the tree, though.
If you are binding the tree, then the Company and Employee nodes will show columns. If you don't want that, it's very easy to turn off. All you have to do is use the ShowColumns property on the Override. In this case, you would probably want to use one of the NodeLevelOverrides to turn it off on a particular level (or in this case 2 levels) of the tree.
The nodes will still have a ColumnSet assigned and you need to set the NodeTextColumn on that ColumnSet to indicate which field the node should use for it's display text when not showing all of the columns. The ColumnSetGenerated event is an ideal place to do this.
Thanks again Mike.
I've made heavy use of the NodeLevelOverrides for the first few levels of the tree, and it worked great. Thanks for the suggestion.
Once I got my custom collection configured, the tree really started looking great. But my work came to a screeching halt when I tried to add an unbound CheckBox column, as you suggested. Here is my attempt:
The column shows up, but it appears as an uncheck-able, useless checkbox, in some state that is neither checked nor unchecked. Just looks like a little green square.
So close... but yet so far. Any ideas?
Setting the CheckEditor's CheckState property does not set the check state for each node. You have to use the UltraTreeNode.SetCellValue method to do that. The "...state that is neither checked nor unchecked..." is just that, the indeterminate state. Since no cell value was set, it defaults to null, which in a three-state checkbox is depicted as CheckState.Indeterminate.
You can handle the InitializeDataNode event to set initial property values of a node that comes into being via data binding, like so:
private void ultraTree1_InitializeDataNode(object sender, InitializeDataNodeEventArgs e){ if ( e.Node.DisplayColumnSetResolved.Columns.Exists("SPCHECKCOLUMN") ) e.Node.SetCellValue( e.Node.DisplayColumnSetResolved.Columns["SPCHECKCOLUMN"], CheckState.Unchecked );}
What you are saying seems great for a bound column, but I was trying to create an unbound column containing a checkbox.
I worked around this issue. Since I have total control of the data bound to the tree, I simply added a boolean property to the necessary object. That eliminated the effort involved with the "unbound" column, and gave me a nice checkbox. With a bit of magic (making the column editable, CellClickAction, etc), it works just fine.
One issue was never resolved. Why is the CheckBox not editable?
I've added an unbound checkbox using the same approach, and I can't check the checkbox.
I just needed to set the CellClickAction
treeHierarchy.Override.CellClickAction =
CellClickAction.EditCell;