Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3391584
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:49:10+00:00 2026-05-18T03:49:10+00:00

I have a TreeView with a parent node and two children node. Each of

  • 0

I have a TreeView with a parent node and two children node. Each of the nodes contain a checkbox stored in a TreeViewItem. I want the two children node checkboxes to be set to IsChecked=true when the user checks the parent node and I want the two children node checkboxes to be IsChecked=false when the user unchecks the parent node.

I have a for loop in which the child node checkboxes are stored in a list. The parent node checkbox check/uncheck event should iterate through the child node checkbox list but I am having a problem aceess the list. For some reason the list equals “nothing” in the parent node check/uncheck event. Can anyone explain how I should be accessing that list?

Here’s My Code:

Public Class Question

Dim childCheckbox As CheckBox
Dim childCheckboxes() As CheckBox

Public Sub Window_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded

    Dim parentCheckbox = New CheckBox
    Dim parentNode = New TreeViewItem

    parentCheckbox.Uid = "All Sites"

    AddHandler parentCheckbox.Checked, AddressOf chkbox_AllChecked
    AddHandler parentCheckbox.Unchecked, AddressOf chkbox_AllUnchecked

    parentCheckbox.Content = "All Sites"
    parentNode.Header = parentCheckbox

    For Each osite In sites

                Dim childNode = New TreeViewItem
                Dim childCheckbox = New CheckBox

                AddHandler childCheckbox.Checked, AddressOf chkbox_Checked
                AddHandler childCheckbox.Unchecked, AddressOf chkbox_Unchecked

                childCheckbox.Uid = osite.SiteName.ToString

                childCheckbox.Content = osite.SiteName.ToString
                childNode.Header = childCheckbox
                parentNode.Items.Add(childNode)

                'Add all childCheckbox to an array for use by parentChildbox methods to check/uncheck all
                childCheckboxes(i) = childCheckbox

                i += 1

            Next
            TreeView1.Items.Add(parentNode)


    End Sub

Private Sub chkbox_AllChecked(ByVal sender As Object, ByVal e As RoutedEventArgs)
    Dim chk = DirectCast(sender, CheckBox)

            'MessageBox.Show(chk.Uid.ToString)


            'This part doesn't work. 
            For Each child In childCheckboxes
                child.IsChecked = True
            Next

    End Sub

Private Sub chkbox_Checked(ByVal sender As Object, ByVal e As RoutedEventArgs)
  Dim chk = DirectCast(sender, CheckBox)

            'MessageBox.Show("Check!")
            MessageBox.Show(chk.Uid.ToString)

End Sub

Private Sub chkbox_Unchecked(ByVal sender As Object, ByVal e As RoutedEventArgs)
   Dim chk = DirectCast(sender, CheckBox)

          'MessageBox.Show("Uncheck!")
           MessageBox.Show(chk.Uid.ToString)

End Sub

End Class

Thanks for the help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T03:49:10+00:00Added an answer on May 18, 2026 at 3:49 am

    Could you try to change the line:

    Dim childCheckboxes() As CheckBox
    

    To:

    Dim childCheckboxes as new list(of CheckBox)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.