Hi
I have an UltraTree (v12.2).
The ViewStyle is set to OutlookExpress to be able to get all the columns from the different levels properly aligned.
One of the column is a checkbox but I need to display the CheckBox only on rows of the first level (other level can leave the cell empty).
How can I achieve that?
I don't set an editor, I only set the DataType to bool and the CheckBox is correctly displayed. Would it be easier if I would specify an editor?
I will try the CreationFilter on Monday.
If the tree is not bound, then you must be adding each node to the tree in code.
So you could add the node and then set the Editor on the cell immediately after adding the node to the tree.
Another option would be to use a CreationFilter, which is a bit more code, but it might be a bit more efficient and also it will work for both a bound and unbound tree.
private void Form1_Load(object sender, EventArgs e) { this.ultraTree1.CreationFilter = new NodeCheckboxCreationFilter(); }
public class NodeCheckboxCreationFilter : IUIElementCreationFilter { void IUIElementCreationFilter.AfterCreateChildElements(UIElement parent) { // Do nothing. } bool IUIElementCreationFilter.BeforeCreateChildElements(UIElement parent) { UltraTreeNodeCellUIElement ultraTreeNodeCellUIElement = parent as UltraTreeNodeCellUIElement; if (null != ultraTreeNodeCellUIElement) { UltraTreeNodeCell cell = ultraTreeNodeCellUIElement.GetContext(typeof(UltraTreeNodeCell)) as UltraTreeNodeCell; if (null != cell) { if (cell.Column.Key == "Boolean 1" && cell.Node.Parent != null) { return true; } } } return false; } }
my tree is not bound. If I am not mistaken, the InitializeDataNode won't be triggered.
What would be the method for an unbound tree?
That depends. I assuming your tree is bound to a data source, and that you are showing a CheckBox in the cell by setting the Editor property of the column to a CheckEditor. If that's the case, you could change the editor on the child node cells to an image renderer.
private EmbeddableImageRenderer embeddableImageRenderer = new EmbeddableImageRenderer(); private void ultraTree1_InitializeDataNode(object sender, Infragistics.Win.UltraWinTree.InitializeDataNodeEventArgs e) { if (null != e.Node.Parent) { e.Node.Cells["Boolean 1"].Editor = embeddableImageRenderer; } }
This is kind've a hack. Basically, you are telling the cell to display as an image, and since the boolean value in the cell cannot be converted into an image, it shows a blank. It also makes it so the user cannot edit the cell, so it works pretty well.
If this doesn't work because one of my assumptions is wrong, then the next best thing would be to use a CreationFilter to prevent the cell from creating the CheckBox elements.
An empty cell would be fine with me. How can I do it?