Hi,
I have a requirement to sort only nodes at level 1. Actually the tree has nodes up to 3 levels. I am setting the UltraTree.NodeLevelOverrides[1].Sort = SortType.Ascending. But after clicking on the column header, when all the nodes are in collapsed state, 0 level nodes are sorted. After expanding root nodes (0 level nodes), if we click on the header, root nodes are not sorted but first level nodes and second level nodes are sorted. Is there any other property i need to set in addition to nodeleveloverride.
Sriram Sarma.
The sort property on the NodeLevelOverrides is only use when sorting nodes that are in Standard ViewStyle. When you are using a style that has columns, the column sorting is used.
So you need to use the AllowSorting property on the ColumnSet. If your tree is bound and you are allowing the tree to generate the ColumnSets automatically, then the ColumnSetGenerated event is probably a good place to do this.
Thank you for the reply. By using AllowSorting property on ColumnSet, how can i sort only particular level nodes.
Regards,
Sarma.
Set the property on the ColumnSet that applies to the level you want.
Typically, each level of data will be using a different ColumnSet - unless you are using a recursive data source and every level has the same structure. In that case, you will need to create a new ColumnSet and assign it to the levels that you want to be different from the others.
Hi Mike,
I am bing the node recursively to the tree in OutLookExpress mode. First i am taking a column collection from the user and creating a columnset with that (treeColumnSet). Later while adding the nodes collection to the tree i am doing like this:
UltraTreeColumnSet columnSet = new UltraTreeColumnSet();
m_ultraTreeNode = node.Nodes.Add(); m_ultraTree.NodeLevelOverrides[m_ultraTreeNode.Level].ColumnSet = columnSet; foreach ( UltraTreeNodeColumn column in treeColumnSet.Columns ) { columnSet.Columns.Add(column); } columnSet.Key = "Level" + m_ultraTreeNode.Level.ToString(); columnSet.AllowSorting = Infragistics.Win.DefaultableBoolean.False; m_ultraTree.ColumnSettings.ColumnSets.Add(columnSet);
And i am adding the cell text like this:
m_ultraTreeNode.SetCellValue(m_ultraTreeNode.NodeLevelOverrides[m_ultraTreeNode.Level].ColumnSet.Columns[item.ColumnIndex], item.CellText);
I am trying to add three level nodes to my tree. After doing like this, only the last level nodes are having cell text.
Image is as follows:
I understood that only the last columnset values are stored but not the previous ones. But unable to fix this.
Can you check where i have made the mistake.
Thanks & regards,
Sriram.
Hi Sriram,
I'm afraid I do not understand your question. Is this somehow related to the other posts in this thread regarding sorting? Or are you asking something completely unrelated?
The code you have here for SetCellValue doesn't make a lot of sense to me. You are only showing the code for one cell - this code isn't looping through all the cell. And I don't see why you would be using the NodeLevelOverrides to set a value on a cell.
Issue: Trying for 'Level Wise sorting in OutLookExpress viewstyle' :
1. To Do this, implemented creating level wise column sets. Please note that column sets are not auto created by ultrawintree in our case.
2. Succeeded in sorting, but with a bug that only last level column set values are shown on treeview (means when the new column set is created, binded to tree and after adding columns to this new columnset by reading zeroeth level columnset columns, the previous column set 'cell values' are replaced as empty text.
3. Follwoing is the code, in which i am creating new columns sets level wise and also find the comments and above mentioned points.
private void AddCellItems(UltraTreeNode node, CellItem item) { //If the item has parent item create a new node to the node received as parameter(child node) if (item.ParentItem != null) { m_ultraTreeNode = node.Nodes.Add(); item.Index = m_ultraTreeNode.Index; if (! (m_levelCollection.Contains(m_ultraTreeNode.Level.ToString())) ) //m_levelCollection contains levels for which column set is already created {
UltraTreeColumnSet columnSet = m_ultraTree.ColumnSettings.ColumnSets.Add("Level" + m_ultraTreeNode.Level.ToString()); //Creating new column set for different level of nodes. Our case consists 0,1,2 levels //***Refer: Point Number 1 m_ultraTree.NodeLevelOverrides[m_ultraTreeNode.Level].ColumnSet = columnSet;
//At this stage, previous level tree node (treeColumnSet) node text is "Infragistics" i.e., m_ultraTree.Nodes[0].Cells[0].Text = "Infragistics"
foreach (UltraTreeNodeColumn column in treeColumnSet.Columns) //treeColumnSet is the zeroeth level column set for which columns are already binded columnSet.Columns.Add(column1);
//At this stage, previous level tree node (treeColumnSet) node text changing to " " (empty text) i.e., m_ultraTree.Nodes[0].Cells[0].Text = ""
//******* After this line 'treeColumnSet'(Zeroeth level columns collection is replacing with newly created 'columnset'(first level) Refer: Pointer number 2 //becoz of which only last added column set values are displayed on tree
columnSet.AllowSorting = Infragistics.Win.DefaultableBoolean.False; m_levelCollection.Add(m_ultraTreeNode.Level, m_ultraTreeNode.Level.ToString(), null, null); }
node = m_ultraTreeNode; } else m_ultraTreeNode = node;
m_ultraTreeNode.Tag = item; m_ultraTreeNode.Key = item.Key; m_ultraTreeNode.Enabled = item.Enable; m_ultraTreeNode.Visible = item.Visible; m_ultraTreeNode.Selected = item.Selected;
if ( item.Bold ) m_ultraTreeNode.Override.NodeAppearance.FontData.Bold = Infragistics.Win.DefaultableBoolean.True;
//Adding the image provided by the control //CTV_002 - image to be appended along with the text if ( item.CellImage != null ) m_ultraTreeNode.Cells[item.ColumnIndex].Appearance.Image = item.CellImage;
m_ultraTreeNode.Cells[item.ColumnIndex].Tag = item;
if ( item.Editable ) m_ultraTreeNode.Cells[item.ColumnIndex].AllowEdit = AllowCellEdit.Full;
if ( item.BackColor != System.Drawing.Color.Empty ) m_ultraTreeNode.Override.NodeAppearance.BackColor = item.BackColor; else SetDefaultBackColor(m_ultraTreeNode); //Adding the cell item text in concerned column m_ultraTreeNode.SetCellValue(m_ultraTree.NodeLevelOverrides[m_ultraTreeNode.Level].ColumnSet.Columns[item.ColumnIndex], item.CellText);
//If Cell Item has child cell items adding them to the list view recursively if ( item.ChildCollection.Count != 0 ) { this.m_collapseAllToolStripMenuItem.Visible = true; this.m_expandAllToolStripMenuItem.Visible = true;
foreach ( CellItem childItem in item.ChildCollection ) AddCellItems(node, childItem);
node.Expanded = item.Expanded; } }
Please find the attachment which shows only last level (ie, 2nd level in our case) values
Thanks in advance and hoping for the positive reply.
Any means to chat with you to explain the situation more clearly.
Its very urgent for us. Please help us to come out from this only blocking issue for our delivery
Hi Brain, Thank you very much for the solution. My problem got resolved by using SortComparer. Thanks & regards, Sriram Sarma.
I believe one solution to this problem is to use the UltraTreeNodeColumn's SortComparer property. The property is of type IComparer, which is a very simple interface that you implement when you want to control how things are sorted. When your IComparer.Compare method is called (as it will be when the column is sorted by the user), you will be passed two objects of type UltraTreeNode. In your case, when the Level property of the nodes (the value will always be the same for both nodes) is not the level you want to sort, return zero and they will remain at the same position within the collection.
Note that setting the UltraTreeColumnSet.AllowSorting property does not initiate a sort, it enables sorting through the user interface. To programmatically trigger a sort for a column, set its 'SortType' property to either 'Ascending' or 'Descending'. Alternatively, you can add it to the ColumnSet's SortedColumns collection.
It's really hard to tell what's going on here from code snippets. Especially with so much code.
Perhaps you can duplicate the issue in a small sample project and post it here and I can take a look.
In continuation to my earlier reply, i would like to add one more point.
1. Level on which nodes need to be sorted will be taken as input through the following method.
public void SortNodesByLevel(int level) { m_ultraTree.NodeLevelOverrides[level].ColumnSet.AllowSorting = Infragistics.Win.DefaultableBoolean.True; }