Results 1 to 7 of 7

Thread: [RESOLVED] How to change value in the Treeview

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Resolved [RESOLVED] How to change value in the Treeview

    Anyone know, how to change the value by typing and new value in the treeview?
    Attached Images Attached Images  
    Last edited by matrik02; Nov 19th, 2007 at 12:05 PM.

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: How to change value in the Treeview

    vb Code:
    1. Private Sub Form_Load()
    2.     TreeView1.Nodes.Add , , "A", "A"
    3.     TreeView1.Nodes.Add , , "B", "B"
    4.     TreeView1.Nodes.Add , , "C", "C"
    5.    
    6.     TreeView1.Nodes.Add "A", tvwChild, "A1", "A1"
    7.     TreeView1.Nodes.Add "A", tvwChild, "A2", "A2"
    8.     TreeView1.Nodes.Add "B", tvwChild, "B1", "B1"
    9.     TreeView1.Nodes.Add "B", tvwChild, "B2", "B2"
    10.    
    11. End Sub
    12. Private Sub Command1_Click()
    13.     Dim tNode As Node
    14.     Set tNode = TreeView1.Nodes("A1")
    15.     tNode.Text = "A1A"
    16.     tNode.Key = "A1A"
    17. End Sub
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: How to change value in the Treeview

    How Can I typing the Value in the treeview?

  4. #4
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: How to change value in the Treeview

    that is a default action.
    selcted the node... then click again. you can change it

    if the list is being saved, then make sure you save the new text
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  5. #5
    Frenzied Member
    Join Date
    Jul 2007
    Posts
    1,306

    Re: How to change value in the Treeview

    you can user StartLabelEdit Method to do this

    Quote Originally Posted by MSDN
    LabelEdit Property Example
    This example initiates label editing when you click the Command button. It allows a Node object to be edited unless it is a root Node. The LabelEdit property must be set to Manual. To try the example, place a TreeView control and a CommandButton on a form. Paste the code into the form's Declarations section. Run the example, select a node to edit, and press the CommandButton.
    Code:
    Private Sub Form_Load()
       Dim nodX As Node
       Dim i As Integer
       TreeView1.LabelEdit = tvwManual   ' Set property to manual.
       Set nodX = TreeView1.Nodes.Add(,,," Node 1")   ' Add first node.
    
       For i = 1 to 5   ' Add 5 nodes.
          Set nodX = TreeView1.Nodes.Add(i,tvwChild,,"Node " & CStr(i + 1))
       Next I
    
       nodX.EnsureVisible   ' Show all nodes.
    End Sub
    
    Private Sub Command1_Click()
       ' Invoke the StartLabelEdit method on the selected node,
       ' which triggers the BeforeLabelEdit event.
       TreeView1.StartLabelEdit 
    End Sub
    
    Private Sub TreeView_BeforeLabelEdit (Cancel as Integer)
       ' If the selected item is the root, then cancel the edit.
       If TreeView1.SelectedItem Is TreeView1.SelectedItem.Root Then
          Cancel = True
       End If
    End Sub
    
    Private Sub TreeView_AfterLabelEdit _
    (Cancel As Integer, NewString As String)
       ' Assume user has entered some text and pressed the ENTER key.
       ' Any nonempty string will be valid.
       If Len(NewString) = 0 Then
          Cancel = True
       End If
    End Sub

    Inseead of a Command Button, you can use a Popup Menu to do this
    eg:

    Code:
    Private Sub TreeView1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
      
        If Button = vbRightButton Then PopupMenu mnuPopupMaster
    
    End Sub
    
    
    Private Sub mnuRenameLabel_Click()
        TreeView1.StartLabelEdit
    End Sub

    IIF(Post.Rate > 0 , , )

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: How to change value in the Treeview

    Thank you both of you.

    I would like to know.. After I change the value to the new value. How I can use the update value?
    Attached Images Attached Images  

  7. #7
    Frenzied Member
    Join Date
    Jul 2007
    Posts
    1,306

    Re: How to change value in the Treeview

    use the AfterLabelEdit event
    eg

    Code:
    Private Sub TreeView1_AfterLabelEdit(Cancel As Integer, NewString As String)
        If MsgBox("Change to " & NewString & "?", vbOKCancel) = vbOK Then
            Cancel = 0
        Else
            Cancel = 1
        End If
    End Sub
    IIF(Post.Rate > 0 , , )

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width