Need Treeview & Get/SaveSetting help

Discussion in 'Programming General' started by Darkgroove, Apr 18, 2009.

Need Treeview & Get/SaveSetting help
  1. Unread #1 - Apr 18, 2009 at 5:48 PM
  2. Darkgroove
    Referrals:
    0

    Darkgroove Guest

    Need Treeview & Get/SaveSetting help

    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
     
  3. Unread #2 - Apr 18, 2009 at 7:05 PM
  4. hampe-92
    Joined:
    Jul 10, 2008
    Posts:
    328
    Referrals:
    0
    Sythe Gold:
    0

    hampe-92 Forum Addict

    Need Treeview & Get/SaveSetting help

    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
    that part would hard coded be the same as;
    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);
    since there is no Parent node for a root node...


    then if we look at the GetSetting method;
    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;
    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:
     
  5. Unread #3 - Apr 18, 2009 at 7:20 PM
  6. Darkgroove
    Referrals:
    0

    Darkgroove Guest

    Need Treeview & Get/SaveSetting help

    Nope, I wouldn't have posted this if the solution was that simple :p

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

    ^ 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.
     
  7. Unread #4 - Apr 18, 2009 at 7:24 PM
  8. hampe-92
    Joined:
    Jul 10, 2008
    Posts:
    328
    Referrals:
    0
    Sythe Gold:
    0

    hampe-92 Forum Addict

    Need Treeview & Get/SaveSetting help

    well I was confused by this sentence;
    but that is really strange, since it's working on my computer :S

    EDIT;
    just gonna test one thing, if you change this code
    to
    and then tell me what the textbox contains
     
  9. Unread #5 - Apr 18, 2009 at 7:29 PM
  10. Darkgroove
    Referrals:
    0

    Darkgroove Guest

    Need Treeview & Get/SaveSetting help

    On the nodes that I stored a value in, the textbox is blank. However, on the rest of the nodes, it contains the text

     
  11. Unread #6 - Apr 18, 2009 at 7:31 PM
  12. hampe-92
    Joined:
    Jul 10, 2008
    Posts:
    328
    Referrals:
    0
    Sythe Gold:
    0

    hampe-92 Forum Addict

    Need Treeview & Get/SaveSetting help

    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...
     
  13. Unread #7 - Apr 18, 2009 at 7:35 PM
  14. Darkgroove
    Referrals:
    0

    Darkgroove Guest

    Need Treeview & Get/SaveSetting help

    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 >_<
     
  15. Unread #8 - Apr 18, 2009 at 7:38 PM
  16. hampe-92
    Joined:
    Jul 10, 2008
    Posts:
    328
    Referrals:
    0
    Sythe Gold:
    0

    hampe-92 Forum Addict

    Need Treeview & Get/SaveSetting help

    huh?o_O

    anyway, you found a solution?
     
  17. Unread #9 - Apr 18, 2009 at 7:41 PM
  18. Darkgroove
    Referrals:
    0

    Darkgroove Guest

    Need Treeview & Get/SaveSetting help

    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
     
  19. Unread #10 - Apr 18, 2009 at 7:46 PM
  20. hampe-92
    Joined:
    Jul 10, 2008
    Posts:
    328
    Referrals:
    0
    Sythe Gold:
    0

    hampe-92 Forum Addict

    Need Treeview & Get/SaveSetting help

    well, If you want to delete all the content of SwimmingAp
    simply write;
    DeleteSetting("SwimmingAp", Nothing)
    or a sub folder
    DeleteSetting("SwimmingAp", "SubFolder")
     
< anyone familiar with qbasic? | [VB.NET] Error When Copying Files >

Users viewing this thread
1 guest


 
 
Adblock breaks this site