?
Solved

Remove selected child node from treeview (vb.net)

Posted on 2011-10-21
2
Medium Priority
?
1,736 Views
Last Modified: 2013-11-12
Hello everyone,

I'm having trouble finding the index number of a selected child in a WPF treeview. What I have so far is attached.  I'm not married to looping through each node either.  If there's a simple way to remove a selected child node, I'd begrateful if someone would share.

Thanks in advance!

 
Private Sub Delete_Node_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Delete_Node.Click
        Dim TreeItems As ItemCollection = Tree.Items
        Dim index As Integer = 0
        ' loops through all parent nodes
        For Each nodes As TreeViewItem In TreeItems
            'loops through the children of the parent
            For i = 0 To nodes.Items.Count - 1
                ' need something here to find if child node is selected and set the index number
                ' index = (the node that's selected)
            Next
        Next
        'TreeViewItem.Items.RemoveAt(index)
    End Sub

Open in new window

0
Comment
Question by:sous2817
  • 2
2 Comments
 
LVL 1

Accepted Solution

by:
sous2817 earned 0 total points
ID: 37006886
Actaully I may have it sorted, but if there are any better / alternative ways I'd like to learn
Private Sub Delete_Node_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Delete_Node.Click
        Dim TreeItems As ItemCollection = Tree.Items
        Dim index As Integer = 0
        ' loops through all parent nodes
        For Each nodes As TreeViewItem In TreeItems
            Dim ChildNodes As ItemCollection = nodes.Items
            'loops through the children of the parent
            For Each ChildNode As TreeViewItem In ChildNodes
                If ChildNode.IsSelected Then
                    ChildNode.Items.RemoveAt(index)
                    Exit For
                End If
                index = index + 1
            Next
        Next
    End Sub

Open in new window

0
 
LVL 1

Author Closing Comment

by:sous2817
ID: 37008071
This solution works, but not sure if there's a better way...
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question