Results 1 to 2 of 2

Thread: Prevent duplicates entries in TreeView

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2004
    Location
    LA
    Posts
    57

    Question Prevent duplicates entries in TreeView

    Hello Guy,

    Once more I need help with TreeView control. I need a way to check for duplicates value in the tree before saving edited node. I wrote some code but for some reason it’s only get the root of the treeview and not the child nodes.

    Code:
    Private Sub TreeView1_AfterLabelEdit1(ByVal sender As System.Object, ByVal e As System.Windows.Forms.NodeLabelEditEventArgs) Handles TreeView1.AfterLabelEdit
    
    Dim node As TreeNode
    
            If Not (e.Label Is Nothing) Then
                If e.Label.Length > 0 Then
                    If e.Label.IndexOfAny(New Char() {"@"c, "."c, ","c, "!"c}) = -1 Then
                        ' Stop editing without canceling the label change.
                        'TreeView1.MousePosition)
    
                        For Each node In TreeView1.Nodes
                            If node.ToString = e.Label.ToString Then
                                e.CancelEdit = True
                            Else
                                e.Node.EndEdit(False)
                            End If
                        Next
    
                    End If
                End If
            End If
    
    End Sub
    Please help

    Thank you.

  2. #2
    Lively Member TLord's Avatar
    Join Date
    Jun 2004
    Posts
    95
    Try this:
    VB Code:
    1. Private Sub TreeView_AfterLabelEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.NodeLabelEditEventArgs) Handles TreeView.AfterLabelEdit
    2.         If e.Label = Nothing Or e.Label.IndexOfAny(New Char() {"@"c, "."c, ","c, "!"c}) <> -1 Then
    3.             e.CancelEdit = True
    4.             Exit Sub
    5.         End If
    6.         Dim Tn As TreeNode
    7.         For Each Tn In rf.Nodes
    8.             If Tn.Text = e.Label Then
    9.                 e.CancelEdit = True
    10.                 Exit For
    11.             End If
    12.         Next
    13.     End Sub
    Do you think my life is easy?
    Do you think it's good to win?
    do you think it's nice to kill?
    Do you think learning is a must?
    Do you think computers are nothing?
    Do you think this post is stupid?
    Do ypu think we're really humen?

    DO YOU THINK IT'S GOOD TO THINK AT ALL? ? ? ! ! !

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