• Log in or sign up for an account here: https://www.sythe.org/login

Need Treeview & Get/SaveSetting help

  • Thread starter Thread starter Darkgroove
  • Start date Start date
D

Darkgroove

Guest
I have an issue with my project, the code below directly affects it.

What is supposed to happen:
User clicks a node on Treeview1. The information stored by pressing the save button previously is brought into 2 textboxes, and a label is used to specify a piece of text.

What is happening:
After pressing the save button, and clicking on another node, the textboxes don't change to the stored figure. They remain blank.

There's no errors. What have I done wrong?

Code:
    Private Sub gSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles gSave.Click
        SaveSetting("SwimmingAp", TreeView1.SelectedNode.Parent.ToString, TreeView1.SelectedNode.ToString, cTime.Text)
        SaveSetting("SwimmingAp", TreeView1.SelectedNode.Parent.ToString, TreeView1.SelectedNode.ToString, gDate.Text)

    End Sub

    Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect

        cTime.Clear()
        gDate.Clear()

        gEvent.Text = "Event: " & TreeView1.SelectedNode.Text & " " & TreeView1.SelectedNode.Parent.Text
        cTime.Text = GetSetting("SwimmingAp", TreeView1.SelectedNode.Parent.ToString, TreeView1.SelectedNode.ToString, cTime.Text)
        gDate.Text = GetSetting("SwimmingAp", TreeView1.SelectedNode.Parent.ToString, TreeView1.SelectedNode.ToString, gDate.Text)

    End Sub
 
well, they does change to the saved text.. but when you click the save button, it only saves the data for the selected node...
this shouldn't be too hard to understand;
Our example tree view;
Code:
+Parent1
   -Child1P1
   -Child2P1

+Parent2
    -Child1P2
    -Child2P2
You start the app.
selects a node, "Child1P1"
in cTime textbox, just let's write "cTime"
in gDate textbox, just let's write "gDate"

now click save button, it's saved.. but if you click another node the data wont show in the textbox since you saved that data for the currently selected node ( Parent1.Child1P1 )

let's take a look at the saving code
SaveSetting("SwimmingAp", TreeView1.SelectedNode.Parent.ToString, TreeView1.SelectedNode.ToString, cTime.Text)
that part would hard coded be the same as;
SaveSetting("SwimmingAp", "Parent1", "Child1P1", cTime.Text)
which means in the registry it would have been saved in the folder SwimmingAp in which a sub folder called Parent1 in which a registry string key named Child1P1 with a value of cTime.text (in our scenario just "cTime" since that's what we wrote in the textbox)

then let's look at the AfterSelect code:

first of, the following code will throw an error if you select a Root node ( e.g Parent1);
gEvent.Text = "Event: " & TreeView1.SelectedNode.Text & " " & TreeView1.SelectedNode.Parent.Text
since there is no Parent node for a root node...


then if we look at the GetSetting method;
cTime.Text = GetSetting("SwimmingAp", TreeView1.SelectedNode.Parent.ToString, TreeView1.SelectedNode.ToString, cTime.Text)
it looks in the registry for the folder SwimmingAp and the checks for a sub folder named as the selected node and then it checks the value of the registry string key named as the child node and grabs the value of that key... so this works fine if there is any data saved for that specific node but if you haven't saved any data for it then there wont be any data to grab...

then just another thing I noticed in the GetSetting method;
cTime.Text = GetSetting("SwimmingAp", TreeView1.SelectedNode.Parent.ToString, TreeView1.SelectedNode.ToString, cTime.Text)
that red is completlly unnecessary since that is the string that should be returned if the registry key wasn't found, but since you clear that text box at the begining it will just return an empty string... and that is field is optional so you could just skip it...

jeez now I have written much for something that should be so simple, try click the node you saved the data for and it should work :confused:
 
Nope, I wouldn't have posted this if the solution was that simple :p

I created an If statement for the gEvent.Text control.

cTime.Text = GetSetting("SwimmingAp", TreeView1.SelectedNode.Parent.ToString, TreeView1.SelectedNode.ToString, cTime.Text)
^ I deleted cTime.Text

I click back to the node that I originally saved the data of, and there's still no value being displayed.
 
well I was confused by this sentence;
and clicking on another node
but that is really strange, since it's working on my computer :S

EDIT;
just gonna test one thing, if you change this code
cTime.Text = GetSetting("SwimmingAp", TreeView1.SelectedNode.Parent.ToString, TreeView1.SelectedNode.ToString, cTime.Text)
to
cTime.Text = GetSetting("SwimmingAp", TreeView1.SelectedNode.Parent.ToString, TreeView1.SelectedNode.ToString, "Key wasn't found, so returning this string")
and then tell me what the textbox contains
 
On the nodes that I stored a value in, the textbox is blank. However, on the rest of the nodes, it contains the text

Key wasn't found, so returning this string
 
On the nodes that I stored a value in, the textbox is blank. However, on the rest of the nodes, it contains the text
which means that it actually do create a key in the registry but either the value is just an empty string or it fails to read it...
 
Using my epic trial and error skills, I found out what it's doing:

When I click save, it stores the date into cTime.Text. Because I was preoccupied with getting the Time to store, I was leaving the date box blank. Tell me why is it doing that?

Edit: gah nevermind. I'm such a stooge >_<
 
Using my epic trial and error skills, I found out what it's doing:

When I click save, it stores the date into cTime.Text. Because I was preoccupied with getting the Time to store, I was leaving the date box blank. Tell me why is it doing that?

Edit: gah nevermind. I'm such a stooge >_<
huh?o_O

anyway, you found a solution?
 
huh?o_O

anyway, you found a solution?

I might as well have been writing:
Code:
cTime.Text = gDate.Text
at the end of the code. The date was storing over the time, so the above statement is true :(
I just have to store it to a different directory location or something.

While this thread is up, I haven't used deletesetting before. How would I do it?

Edit: Nevermind, got it :D
 
well, If you want to delete all the content of SwimmingAp
simply write;
DeleteSetting("SwimmingAp", Nothing)
or a sub folder
DeleteSetting("SwimmingAp", "SubFolder")
 
Back
Top