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
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

TreeviewAdv (Load from datasource)

Thread ID:





5159 Jun 23,2003 01:43 AM UTC Mar 20,2018 05:12 AM UTC WinForms 3
Tags: Tools
Bob Towle
Asked On June 23, 2003 01:43 AM UTC

I want to load States and Cities (within those states) into a TreeViewAdv control. The results should look like: - Texas Abilene Houston San Antonio - Connecticut New Haven Hartford etc. The data resides in a SQL Server Table. I can put the dataset into a loop easy enough, but I can't figure out how to tell the treeviewadv to load a state (as a parent node) and a city (as a child node). I know which is which from the data, I just can't see how to programmatically load them into the TreeViewADV. Here is the code I'm running, the results end up recursing over and over again. Private Sub treeViewAdv2_BeforeExpand(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Tools.TreeNodeAdvBeforeExpandEventArgs) Handles treeViewAdv2.BeforeExpand If e.Node.ExpandedOnce Then Return Dim ds As New DataSet Dim da As SqlDataAdapter Dim cn As New SqlConnection("server=(local);uid=sa;pwd=;database=Sample") Dim x As Integer da = New SqlDataAdapter("select * from StatesCities order by IsCity", cn) da.Fill(ds, "StatesCities") For x = 0 To ds.Tables(0).Rows.Count - 1 Dim StateCityNode As String = RTrim(ds.Tables(0).Rows(x).Item("cStateCityName").ToString()) Dim node As New TreeNodeAdv(StateCityNode) e.Node.Nodes.Add(node) Next End Sub If you can show me how to do the promoting and demoting of the nodes as they are loaded, I would be most grateful (Please, in VB.NET)

Davis Jebaraj [Syncfusion]
Replied On June 24, 2003 01:19 PM UTC

Hi Bob, I have attached a sample that uses a TreeData library that we have developed that shows databinding a TreeViewAdv to a database. The library itself is in c# and the code is included. The sample that uses this library is in VB.NET and you only have to make minor changes in the VB.NET code to make it work with your project. http://www.syncfusion.com/support/user/uploads/treeadvgridsync.zip Please try this and let us know. Regards, Davis

Adam Thompson
Replied On March 20, 2018 02:27 AM UTC

I would be interested in seeing the example project as I have a need to databind to a windows forms treeview control.

The link at http://www.syncfusion.com/support/user/uploads/treeadvgridsync.zip is dead.

Gokul Sainarayanan [Syncfusion]
Replied On March 20, 2018 05:12 AM UTC

Hi Adam,

We can load the TreeViewAdv by iterating each element from the DataTable and update the TreeView item. For more information regarding this, please refer the below KB link.

KB Link: https://www.syncfusion.com/kb/7985/how-to-populate-treeviewadv-from-datatable

Gokul S


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon