cocoWang
asked on
How to synchronize nodes data between two related treeviews
I have two treeviews (treeview A and treeveiw B), the nodes are as below
Treeview A
Soccer
player1
player2
player3
Basketball
player1
player5
Volleyball
player2
player4
Treeview B
player1
Soccer
Basketball
player2
soccer
Volleyball
player3
Soccer
player4
Volleyball
player5
Basketball
If I do the function of add/edit/delete a player in Treeview A, how can the Treeview B automatically get refreshed and synchroized with the updated display of nodes? In fact, these two treeviews nodes are displayed from 3 SQL 2000 tables. I would appreciate if someone has done such kind of task and give me some kind of guidance.
Treeview A
Soccer
player1
player2
player3
Basketball
player1
player5
Volleyball
player2
player4
Treeview B
player1
Soccer
Basketball
player2
soccer
Volleyball
player3
Soccer
player4
Volleyball
player5
Basketball
If I do the function of add/edit/delete a player in Treeview A, how can the Treeview B automatically get refreshed and synchroized with the updated display of nodes? In fact, these two treeviews nodes are displayed from 3 SQL 2000 tables. I would appreciate if someone has done such kind of task and give me some kind of guidance.
Well the simplest thing to do is to write a refres() function which simple clears the treeview and repopulates it through the queries. Then you just call that refresh after every add/edit/delete operation.
ASKER
Thanks for your advice, The original treeview was populated from the dataset generated from 3 tables, I have successfully generated an multi-dimensional array to store data of those nodes from the first treeveiw to this array, my co-worker suggested me to use collection class to collect data of nodes, clear the second treeview, then populate the second treeview with data from the collection class.
I have never done this before, but I will try it through the collection class anyway, and see if it works.
When my coding is done, I may present some questions here if I get problems.
I have never done this before, but I will try it through the collection class anyway, and see if it works.
When my coding is done, I may present some questions here if I get problems.
I would take a look at the MVC pattern it offers a much more elegant solution to this problem.
ASKER
MVC is used for JAVA, I checked VB.NET, it is not VB technology, I have to pass this suggestion, unless you think differently, as a matter of fact, I know nothing about MVC, my friend told me that is Model View Controller used specifically for JAVA.
LMAO
from wikipedia: In software engineering, design patterns are standard solutions to common problems in software design. The phrase was introduced to computer science in 1995 by the text Design Patterns: Elements of Reusable Object-Oriented Software. The scope of the term remained a matter of dispute into the next decade. Algorithms are not thought of as design patterns, since they solve computational problems rather than design problems. Typically, a design pattern is thought to encompass a tight interaction of a few classes and objects.
one of the aspects about a pattern is that they are language inspecific ... in fact they are most commonly expressed in UML. The pattern describes the contracts between the objects as well as the objects themselves but it only encompasses a design level of detail.
Saying that MVC has to do with JAVA is like saying a SINGLETON has to do with .NET .... they are not related, simply because a given platform makes use of a pattern does not preclude its use elsewhere.
http://www.devx.com/dotnet/Article/10186/0/page/3
http://www.c-sharpcorner.com/Code/2003/Feb/MVCDesign.asp
Greg
from wikipedia: In software engineering, design patterns are standard solutions to common problems in software design. The phrase was introduced to computer science in 1995 by the text Design Patterns: Elements of Reusable Object-Oriented Software. The scope of the term remained a matter of dispute into the next decade. Algorithms are not thought of as design patterns, since they solve computational problems rather than design problems. Typically, a design pattern is thought to encompass a tight interaction of a few classes and objects.
one of the aspects about a pattern is that they are language inspecific ... in fact they are most commonly expressed in UML. The pattern describes the contracts between the objects as well as the objects themselves but it only encompasses a design level of detail.
Saying that MVC has to do with JAVA is like saying a SINGLETON has to do with .NET .... they are not related, simply because a given platform makes use of a pattern does not preclude its use elsewhere.
http://www.devx.com/dotnet/Article/10186/0/page/3
http://www.c-sharpcorner.com/Code/2003/Feb/MVCDesign.asp
Greg
ASKER
Greg,
Thanks for your advice, but I really knows nothing about MVC, and I do not have time to learn this as deadline is not too far away from solving this problem. I have to find out the solution that I can pick up quickly.
Thanks for your advice, but I really knows nothing about MVC, and I do not have time to learn this as deadline is not too far away from solving this problem. I have to find out the solution that I can pick up quickly.
MVC would say to register a changed data event from the data object to the treeview to only update the specific node as opposed to reloading the entire treeview ... levels of complexity easier and a much cleaner interface. I understand that solutions are often needed quickly but I would go out and buy a book (GoF design patterns comes to mind) to learn such patterns as they create far cleaner interfaces (what if you have 5000 elements in your treeview?! a reload may take a few seconds and is surely unnecesary to remove a single node).
Good luck,
Greg
Good luck,
Greg
ASKER
Greg,
Thanks, I don't mind to go out and buy a book as you suggested if I get the free time, I believe it must be worth to learn this new and efficient technology. You might help me with a simple question at this moment.
I have actually 3 treeviews, and I only allow the first treeview to do add/edit/delete function on the nodes, and the 3 treeviews are loaded from 5 tables, they are WFOrg(primary key field WFOrgID),
WFOrgRole(Primary key WFOrgRoleID, WFOrgID, WFRoleID),
WFOrgRoleUser(primary key WFOrgRoleUserID, WFOrgID, WFRoleID, MLUserID),
WFRole(primary key WFRoleID, description)
and MLUser(primary key MLUserID, namefirst, namelast).
Those tables are related with one another by their primary key or fields inside the table. I successfully load them with following codes.
Private Sub frmWFORU_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Load treeviews with data from dataset
g_oTv = TreeView3
Dim myConnString As String = "Data Source=PAR-SQL1,1433;Initi al Catalog=ScratchDB;Integrat ed Security=SSPI;"
Dim CN As SqlConnection = Connect(myConnString)
Dim DAORg As New SqlClient.SqlDataAdapter(" SELECT WFOrgID, Description FROM WFOrg ", CN)
Dim DAUniqueUser As New SqlClient.SqlDataAdapter(" SELECT DISTINCT U.namefirst + ' ' + U.namelast, U.MLUserID " & _
" FROM MLUser as U INNER JOIN WFOrgRoleUser as ORU on U.MLUserID = ORU.MLUserID " & _
" WHERE not Signature is NULL", CN)
Dim DARole As New SqlClient.SqlDataAdapter(" SELECT R.Description, ORole.WFRoleID, " & _
" ORole.WFOrgID FROM WFOrgRole as ORole INNER JOIN WFRole as R " & _
" on ORole.WFRoleID = R.WFRoleID Where WForgID in (SELECT WFOrgID FROM WFOrg)", CN)
Dim DAUser As New SqlClient.SqlDataAdapter(" SELECT U.namefirst + ' ' + U.namelast, " & _
" ORU.WFRoleID FROM MLUser as U INNER JOIN WFOrgRoleUser as ORU on U.MLUserID = ORU.MLUserID " & _
" where WFRoleID in (SELECT WFRoleID FROM WFOrgRole where WFOrgID " & _
" in(SELECT WFOrgID FROM WFOrg)) order by U.namefirst + ' ' + U.namelast", CN)
Dim DAUserRole As New SqlClient.SqlDataAdapter(" SELECT DISTINCT R.Description, ORole.WFRoleID, ORU.MLUserID, " & _
" ORole.WFOrgID FROM WFOrgRole as ORole INNER JOIN WFRole as R on ORole.WFRoleID = R.WFRoleID " & _
" INNER JOIN WFOrgRoleUser as ORU on ORU.WFRoleID = ORole.WFRoleID INNER JOIN WFOrg as O " & _
" on ORU.WFOrgID = O.WFOrgID Where ORU.WForgID in (SELECT WFOrgID FROM WFOrg)", CN)
DAORg.Fill(dset, "dtOrg")
DARole.Fill(dset, "dtRole")
DAUser.Fill(dset, "dtUser")
DAUserRole.Fill(dset, "dtUserRole")
DAUniqueUser.Fill(dset, "dtUniqUser")
CN.Close()
'Create a data relation object to facilitate the relationship between the WFOrg, WFOrgRole and WFOrgRoleUser tables.
dset.Relations.Add("OrgToR ole", dset.Tables("dtOrg").Colum ns("WFOrgI D"), dset.Tables("dtRole").Colu mns("WFOrg ID"))
dset.Relations.Add("RoleTo User", dset.Tables("dtRole").Colu mns("WFRol eID"), dset.Tables("dtUser").Colu mns("WFRol eID"))
dset.Relations.Add("UserTo Role", dset.Tables("dtUniqUser"). Columns("M LUserID"), dset.Tables("dtUserRole"). Columns("M LUserID"))
TreeView3.Nodes.Clear()
Dim parentrow As DataRow
Dim ParentTable As DataTable
Dim ChildTable As DataTable
ParentTable = dset.Tables("dtOrg")
' Display the first panel OrgRoleUser treeview
For Each parentrow In ParentTable.Rows
Dim parentnode As TreeNode
parentnode = New TreeNode(parentrow.Item(1) )
parentnode.Tag = parentrow.Item(0)
TreeView3.Nodes.Add(parent node)
Dim childrow As DataRow
Dim childnode As TreeNode
childnode = New TreeNode
For Each childrow In parentrow.GetChildRows("Or gToRole")
childnode = parentnode.Nodes.Add(child row(0))
childnode.Tag = childrow("WFRoleID")
Dim childrow2 As DataRow
Dim childnode2 As TreeNode
childnode2 = New TreeNode
For Each childrow2 In childrow.GetChildRows("Rol eToUser")
childnode2 = childnode.Nodes.Add(childr ow2(0))
childnode2.Tag = childrow2("WFRoleID")
Next childrow2
Next childrow
Next parentrow
' Display the second panel RoleUser treeview
ChildTable = dset.Tables("dtRole")
TreeView2.Nodes.Clear()
For Each parentrow In ChildTable.Rows
Dim parentnode As TreeNode
parentnode = New TreeNode(parentrow(0))
TreeView2.Nodes.Add(parent node)
Dim childrow As DataRow
Dim childnode As TreeNode
childnode = New TreeNode
For Each childrow In parentrow.GetChildRows("Ro leToUser")
childnode = parentnode.Nodes.Add(child row(0))
childnode.Tag = childrow("WFRoleID")
Next childrow
Next parentrow
' Display the third panel UserRole treeview
ChildTable = dset.Tables("dtUniqUser")
TreeView1.Nodes.Clear()
For Each parentrow In ChildTable.Rows
Dim parentnode As TreeNode
parentnode = New TreeNode(parentrow(0))
TreeView1.Nodes.Add(parent node)
Dim childrow As DataRow
Dim childnode2 As TreeNode
childnode2 = New TreeNode
For Each childrow In parentrow.GetChildRows("Us erToRole")
childnode2 = parentnode.Nodes.Add(child row(0))
childnode2.Tag = childrow("WFRoleID")
Next childrow
Next parentrow
' Build up collections for WFOrg, WFOrgRole, WFOrgRoleUser, MLUser, WFRole
'Dim clsOrg As New MDWFOrgs
Dim tmpOrg As MDWFOrgs
Dim i As Int16
i = tmpOrg.mcolClassObj.Count( )
End Sub
The first treeview will look like this:
PA provider repricing
PA code review
BRT
BRT Leader
Andy Jarvius
Tom Cruise
...................
The first level is Org(for organization), the second level is for Role the third level is the user name.
My question is : When I add a node on any level of the tree, for instance the bottom level on the user, how to find out the related RoleID and OrgID of the second and first level?
Once I know the these data, I can use stored procedure to insert or update the table data, and repopulate them that will automatically synchronize the nodes on the second and third treeview.
Thanks, I don't mind to go out and buy a book as you suggested if I get the free time, I believe it must be worth to learn this new and efficient technology. You might help me with a simple question at this moment.
I have actually 3 treeviews, and I only allow the first treeview to do add/edit/delete function on the nodes, and the 3 treeviews are loaded from 5 tables, they are WFOrg(primary key field WFOrgID),
WFOrgRole(Primary key WFOrgRoleID, WFOrgID, WFRoleID),
WFOrgRoleUser(primary key WFOrgRoleUserID, WFOrgID, WFRoleID, MLUserID),
WFRole(primary key WFRoleID, description)
and MLUser(primary key MLUserID, namefirst, namelast).
Those tables are related with one another by their primary key or fields inside the table. I successfully load them with following codes.
Private Sub frmWFORU_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Load treeviews with data from dataset
g_oTv = TreeView3
Dim myConnString As String = "Data Source=PAR-SQL1,1433;Initi
Dim CN As SqlConnection = Connect(myConnString)
Dim DAORg As New SqlClient.SqlDataAdapter("
Dim DAUniqueUser As New SqlClient.SqlDataAdapter("
" FROM MLUser as U INNER JOIN WFOrgRoleUser as ORU on U.MLUserID = ORU.MLUserID " & _
" WHERE not Signature is NULL", CN)
Dim DARole As New SqlClient.SqlDataAdapter("
" ORole.WFOrgID FROM WFOrgRole as ORole INNER JOIN WFRole as R " & _
" on ORole.WFRoleID = R.WFRoleID Where WForgID in (SELECT WFOrgID FROM WFOrg)", CN)
Dim DAUser As New SqlClient.SqlDataAdapter("
" ORU.WFRoleID FROM MLUser as U INNER JOIN WFOrgRoleUser as ORU on U.MLUserID = ORU.MLUserID " & _
" where WFRoleID in (SELECT WFRoleID FROM WFOrgRole where WFOrgID " & _
" in(SELECT WFOrgID FROM WFOrg)) order by U.namefirst + ' ' + U.namelast", CN)
Dim DAUserRole As New SqlClient.SqlDataAdapter("
" ORole.WFOrgID FROM WFOrgRole as ORole INNER JOIN WFRole as R on ORole.WFRoleID = R.WFRoleID " & _
" INNER JOIN WFOrgRoleUser as ORU on ORU.WFRoleID = ORole.WFRoleID INNER JOIN WFOrg as O " & _
" on ORU.WFOrgID = O.WFOrgID Where ORU.WForgID in (SELECT WFOrgID FROM WFOrg)", CN)
DAORg.Fill(dset, "dtOrg")
DARole.Fill(dset, "dtRole")
DAUser.Fill(dset, "dtUser")
DAUserRole.Fill(dset, "dtUserRole")
DAUniqueUser.Fill(dset, "dtUniqUser")
CN.Close()
'Create a data relation object to facilitate the relationship between the WFOrg, WFOrgRole and WFOrgRoleUser tables.
dset.Relations.Add("OrgToR
dset.Relations.Add("RoleTo
dset.Relations.Add("UserTo
TreeView3.Nodes.Clear()
Dim parentrow As DataRow
Dim ParentTable As DataTable
Dim ChildTable As DataTable
ParentTable = dset.Tables("dtOrg")
' Display the first panel OrgRoleUser treeview
For Each parentrow In ParentTable.Rows
Dim parentnode As TreeNode
parentnode = New TreeNode(parentrow.Item(1)
parentnode.Tag = parentrow.Item(0)
TreeView3.Nodes.Add(parent
Dim childrow As DataRow
Dim childnode As TreeNode
childnode = New TreeNode
For Each childrow In parentrow.GetChildRows("Or
childnode = parentnode.Nodes.Add(child
childnode.Tag = childrow("WFRoleID")
Dim childrow2 As DataRow
Dim childnode2 As TreeNode
childnode2 = New TreeNode
For Each childrow2 In childrow.GetChildRows("Rol
childnode2 = childnode.Nodes.Add(childr
childnode2.Tag = childrow2("WFRoleID")
Next childrow2
Next childrow
Next parentrow
' Display the second panel RoleUser treeview
ChildTable = dset.Tables("dtRole")
TreeView2.Nodes.Clear()
For Each parentrow In ChildTable.Rows
Dim parentnode As TreeNode
parentnode = New TreeNode(parentrow(0))
TreeView2.Nodes.Add(parent
Dim childrow As DataRow
Dim childnode As TreeNode
childnode = New TreeNode
For Each childrow In parentrow.GetChildRows("Ro
childnode = parentnode.Nodes.Add(child
childnode.Tag = childrow("WFRoleID")
Next childrow
Next parentrow
' Display the third panel UserRole treeview
ChildTable = dset.Tables("dtUniqUser")
TreeView1.Nodes.Clear()
For Each parentrow In ChildTable.Rows
Dim parentnode As TreeNode
parentnode = New TreeNode(parentrow(0))
TreeView1.Nodes.Add(parent
Dim childrow As DataRow
Dim childnode2 As TreeNode
childnode2 = New TreeNode
For Each childrow In parentrow.GetChildRows("Us
childnode2 = parentnode.Nodes.Add(child
childnode2.Tag = childrow("WFRoleID")
Next childrow
Next parentrow
' Build up collections for WFOrg, WFOrgRole, WFOrgRoleUser, MLUser, WFRole
'Dim clsOrg As New MDWFOrgs
Dim tmpOrg As MDWFOrgs
Dim i As Int16
i = tmpOrg.mcolClassObj.Count(
End Sub
The first treeview will look like this:
PA provider repricing
PA code review
BRT
BRT Leader
Andy Jarvius
Tom Cruise
...................
The first level is Org(for organization), the second level is for Role the third level is the user name.
My question is : When I add a node on any level of the tree, for instance the bottom level on the user, how to find out the related RoleID and OrgID of the second and first level?
Once I know the these data, I can use stored procedure to insert or update the table data, and repopulate them that will automatically synchronize the nodes on the second and third treeview.
ASKER
Sorry I never know we have these regulations, I will follow these rules in the future, please refund to me this time. The matter of fact is I finally figured out the solution by myself.
Thanks!
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.