Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
110
UltraTree with DataBind is duplicating data
posted

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?

Parents
No Data
Reply
  • 1500
    Offline posted

    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 Tonev
    Software Developer
    Infragistics

Children