|
-
Dec 14th, 2003, 08:27 PM
#1
Thread Starter
Registered User
save control
i want to save a treeview object when the user clicks a button in the application, so that the user can load again anytime, even if the application is closed and reopened. any ideas how to do this?
-
Dec 15th, 2003, 04:20 PM
#2
Hyperactive Member
post some more details as from what you describe most of usewould populate the treeview from a dataset, containing the last saved information
-
Dec 15th, 2003, 04:57 PM
#3
Thread Starter
Registered User
datasets
you're right. a dataset is probably a more elegant way of doing this. do you have a link where i can find a tutorial on working with datasets?
thanks...
-
Dec 15th, 2003, 06:00 PM
#4
Hyperactive Member
better strill here is some working code!, now remember I have left out the dim statementz and it maybe a little dificult to follow, so if you have a follow up request feel free to ask:
But the basic logic is there:
Dim OledbStr As String = "Select * from Localities "
Dim Cmd1 As OleDbCommand = New OleDbCommand(OledbStr, Cn1)
Cn1.Open()
Cn2.Open()
Cn3.Open()
Dim dr1 As OleDbDataReader = Cmd1.ExecuteReader()
TreeView1.BeginUpdate()
TreeView1.Nodes.Clear()
Dim AllNode As New ViewNode("All locations", 0, 0)
TreeView1.Nodes.Add(AllNode)
Dim TreePos As Integer = 1
While dr1.Read
Dim LocNode As New ViewNode(dr1("Locality"), 0, 0)
AllNode.Nodes.Add(LocNode)
OledbStr = "Select * from PropAvail where Locality = '" & Trim(dr1("Locality")) & "'"
Dim Cmd2 As OleDbCommand = New OleDbCommand(OledbStr, Cn2)
Dim dr2 As OleDbDataReader = Cmd2.ExecuteReader()
While dr2.Read
Dim PropNode As New ViewNode((Trim(dr2("Adr1")) & "," & Trim(dr2("Adr2"))), dr2("Proprty"), 0)
LocNode.Nodes.Add(PropNode)
OledbStr = "Select * from PropUnitAvailable where Proprty = " & CStr(dr2("Proprty"))
Dim Cmd3 As OleDbCommand = New OleDbCommand(OledbStr, Cn3)
Dim dr3 As OleDbDataReader = Cmd3.ExecuteReader()
Dim Headline As String
While dr3.Read
If IsDBNull(dr3("Headline")) Then
Headline = "No Headline"
Else
Headline = dr3("Headline")
End If
Dim UnitNode As New ViewNode((Trim(dr3("PropertyAdr")) & "," & Trim(Headline)), dr3("Proprty"), dr3("Unit"))
PropNode.Nodes.Add(UnitNode)
End While
dr3.Close()
Cmd3 = Nothing
End While
dr2.Close()
Cmd2 = Nothing
End While
TreeView1.EndUpdate()
Iterms such as ViewNode are classes which inherit the treenode and add adddtional properties
here is the class which defines viewnode:
Public Class ViewNode
Inherits TreeNode
Public Name As String
Public Proprty As Integer
Public Unit As Integer
Sub New(ByVal Title As String, ByVal Proprty1 As Integer, ByVal Unit1 As Integer)
MyBase.New()
Name = Title
Proprty = Proprty1
Unit = Unit1
Me.Text = Name
End Sub
End Class
Not your complete answer just some sample code to point you in the right direction
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|