We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

expand root node after binding data unsuccess

Hi


I checked the current forum to help me, but without success


I am using WinForms Essential version 20.1.0.47.


I try to expand root node after binding data with the method "Binding to Self-Referencing Data".


1rst step I bind data :


My object class is :

    public partial class Category
    {
        public Int64 pkCategory { get; set; }
        public String Name { get; set; }
        public Int64 fkCategoryParent { get; set; }
        public String NumeroDelcampe { get; set; }
    }


the datasource binding configuration is :

this.treeViewAdvCategories.SelfRelationRootValue = "0";
this.treeViewAdvCategories.DisplayMember = "Name";
this.treeViewAdvCategories.ParentMember = "fkCategoryParent";
this.treeViewAdvCategories.ChildMember = "pkCategory";
this.treeViewAdvCategories.ValueMember = "pkCategory";

At this step all works right.


My current source code :

// get datatable
using (ProductsDB productsDB = new ProductsDB())
{
dataTableCategories =
productsDB.GetAll<Category>()
.OrderBy(x => x.Name)
.ToDataTable();
}


// configure "Binding to Self-Referencing Data" Synfusion TreeViewAdv
this.treeViewAdvCategories.SelfRelationRootValue = "0";
this.treeViewAdvCategories.DisplayMember = "Name";
this.treeViewAdvCategories.ParentMember = "fkCategoryParent";
this.treeViewAdvCategories.ChildMember = "pkCategory";
this.treeViewAdvCategories.ValueMember = "pkCategory";


// rename the root element
foreach (DataRow row in dataTableCategories.Rows)
{
if (row[this.treeViewAdvCategories.ParentMember].ToString() == "0")
{
row["Name"] = "<Root>";
}
}


// bind data
this.treeViewAdvCategories.DataSource = dataTableCategories;


2nd step : Now, I try to expand the root node.


My source code becomes

// get datatable
using (ProductsDB productsDB = new ProductsDB())
{
dataTableCategories =
productsDB.GetAll<Category>()
.OrderBy(x => x.Name)
.ToDataTable();
}


// configure "Binding to Self-Referencing Data" Synfusion TreeViewAdv
this.treeViewAdvCategories.SelfRelationRootValue = "0";
this.treeViewAdvCategories.DisplayMember = "Name";
this.treeViewAdvCategories.ParentMember = "fkCategoryParent";
this.treeViewAdvCategories.ChildMember = "pkCategory";
this.treeViewAdvCategories.ValueMember = "pkCategory";


// rename the root element
foreach (DataRow row in dataTableCategories.Rows)
{
if (row[this.treeViewAdvCategories.ParentMember].ToString() == "0")
{
row["Name"] = "<Root>";
}
}


// bind data
this.treeViewAdvCategories.DataSource = dataTableCategories;
this.treeViewAdvCategories.Refresh();


// expand root node
try
{
TreeNodeAdv node = this.treeViewAdvCategories.Nodes[0];
node.ExpandAll();
}
catch(Exception ex)
{
logger.Error("Expand error:");
logger.Error(ex);
}


But here, the count for this.treeViewAdvCategories.Nodes is always zero.

Maybe it normal, but i expected a non-zero value for count.


My way of expanding root node is right ?

Could you help me ?

BR

Cyrille






Attachment: Pictures_6ba1c7f.7z

3 Replies

SJ Sathiyathanam Jeyakumar Syncfusion Team November 7, 2022 07:09 PM UTC


Hi Cyrille,


Sorry for the delay, we are checking the reported issue and will update you with further details on November 9, 2022. Appreciate your patience until then.


Regards,

Sathiyathanam





SJ Sathiyathanam Jeyakumar Syncfusion Team November 9, 2022 04:10 PM UTC

Hi Cyrille,

You can expand all the nodes based on the root nodes with the dispatcher in DataSourceChanged event. Refer the below code snippets and the sample to get the more information.

//Event subscription

this.treeViewAdv1.DataSourceChanged += OnDataSourceChanged;

this.Load += OnLoad;

 

private void OnLoad(object sender, EventArgs e)

{

    //assign the DataSource

    treeViewAdv1.DataSource = dataTable1;            

}

 

//Event customization

private void OnDataSourceChanged(object sender, DataSourceChangedEventArgs e)

{

    //Here expand the root node

    treeViewAdv1.BeginInvoke(new Action(() =>

    {

        //here expand the node

        TreeNodeAdv node = this.treeViewAdv1.Root;

        node.ExpandAll();

    }));

}


Sample:https://www.syncfusion.com/downloads/support/directtrac/general/ze/Sample-1019009211.zip

Please check your data's count whether the data is properly fetched from db or not.

Regards

Sathiyathanam



PG Peter Groft March 30, 2023 09:08 AM UTC

To expand the root node after binding data unsuccessfully, you may need to investigate the cause of the issue and determine the appropriate solution. Here are a few steps you can take:

Check for errors: Start by checking for any errors that may have occurred during the data binding process. Look for error messages in your console or log files and try to diagnose the issue.

Verify data source: Ensure that the data source is correctly bound to the root node. Verify that the data source contains the necessary data and that it is in the correct format. If the data source is incorrect or malformed, you may need to fix it before attempting to expand the root node.

Check expand settings: If the data source is correct, check the expand settings for the root node. Make sure that the node is set to expand by default or that it can be expanded manually. Check that any expand/collapse buttons or icons are functioning correctly.

Refresh the view: If the above steps do not resolve the issue, try refreshing the view or reloading the page. This can sometimes reset the state of the application and allow the root node to expand correctly.

Debug the code: If none of the above steps work, you may need to debug the code to identify the root cause of the issue. Use your debugging tools to step through the code and identify any issues that may be preventing the root node from expanding.


This May Help,
Peter


Loader.
Live Chat Icon For mobile
Up arrow icon