I have an UltraTree set up with DataBinding.
The DataSet is one table, which is self-referencing for its heirarchy. Each record has an "ID" field and a "ParentId" field.
I've set up the DataSet like this:
_level1DataSet.Tables.Add(GetTable("Level1")); _level1DataSet.Relations.Add("Active", TreeViewItems.Tables["Level1"].Columns["id"], TreeViewItems.Tables["Level1"].Columns["parent_id"], false); private DataTable GetTable(string tableName) { try { var selectCommandText = string.Format(SELECT_COMMAND_TEMPLATE, tableName); var dataAdapter = new OleDbDataAdapter(selectCommandText, this.OleDbConnection); var table = new DataTable(tableName); dataAdapter.Fill(table); return table; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error getting data"); } return null; } private const string SELECT_COMMAND_TEMPLATE = "SELECT display_name, orig_display_name, id,parent_id, item_type, item_state, item_link, doc_seq FROM [{0}]";
I reference the DataSet thus:
ppTreeView.Override.ShowExpansionIndicator = ShowExpansionIndicator.CheckOnDisplay; ppTreeView.DataSource = propelDataSource.TreeViewItems;
I also have set up InitializeDataNode to manipulate the records, and if needed I can provide that code (but I don't believe the issue to be there).
When the data is displayed, I'm getting the following result:
In the above picture, the folders are showing properly at the top (under "root"). However, the folders seem to be repeating themselves on the same level as root, and they shouldn't be there.
I've verified that the dataset accurately reflects the data located in the database. The documents that are also on the root level belong there - just the folders are extra.
What could be causing this?
Hello,
Thank you for posting on our forums.
My best guess is that there are some nodes in the table, that are at root level, but are supposed to be children in the tree based on data relations. What I mean is, when tree is populated, it first creates all root nodes, and then it uses relations to create the child nodes. So the duplicates must be on root level, and related as children at the same time.
So what you can do is to check if there are nodes at root level having parentID and hide them. Something like:
if (e.Node.Parent == null && e.Node.Cells[Parent].Value != DBNull.Value) { e.Node.Visible = false; return; }
Please let me know if this helps.
Sincerely,
Tihomir TonevSoftware DeveloperInfragistics
Should this be placed in InitializeDataNode?
Yes, InitializeDataNode would be the place to do that.
Ok, I inserted that code snippet, and it appears that every single node matches that criteria, in that they have no Parent defined, yet have a value in the Cells["Parent_id"] property. Thus, when this snippet is in place, no data is shown at all.
Does this help define what the actual issue is?
How are the DataRelations set? There should be parents if the relations are configured. Can you send an isolated sample? just the configured DataTable bound to a tree?
Looking forward to your reply.
My code only hides nodes, so duplicating them cannot be caused by it.
If you are able to isolate this issue in a small sample and give me the exactly steps (and other details like Operating System, version controls and etc.), which I should follow in order to reproduce this issue on my machine, I will be glad to investigate this further for you. Without sample, we only could make guesses, what could be the reason for this issue.
I'm waiting for your feedback.
TIhomir TonevSoftware DeveloperInfragistics
As part of my debugging effort, I also printed the band name (e.Node.BandName) for each node that was processed in InitializeDataNode. I expect to have only one (set in the creation of DataRelation), but I actually have two. One is named "Level1" (the name of the table), and the second one is named "Active" (the name of the DataRelation).
The tree is databound via:
var propelDataSource = new DataHelper(); treeView.DataSource = propelDataSource.TreeViewItems; treeView.DataMember = "Level1";
The DataHelper instantiates and prepares the dataset here:
_level1DataSet.Tables.Add(GetTable("Level1")); _level1DataSet.Relations.Add("Active", TreeViewItems.Tables["Level1"].Columns["id"], TreeViewItems.Tables["Level1"].Columns["parent_id"], false);
_level1DataSet is an internal variable to DataHelper; TreeViewItems (which is referenced in the first snipped of code above) is a property that returns that value.
Something else I've noticed: I put a List object in the code for testing purposes. Each time a node triggers the if statement you provided, before it returns, I add the ID columns to that list. There are 167 records in the database I'm using; however, after loading, my list contains 334 - exactly twice the count.
I feel like the tree is being drawn, and thus InitializeDataNode is being called, two different times. There is only one reference to InitializeDataNode (set within the tree control's properties). Not sure how it's being called twice.