Treeview checkbox problem

I need help on the treeview checkbox

Page 1 of 1

7 Replies - 26305 Views - Last Post: 03 January 2011 - 01:59 PM Rate Topic: -----

#1 Stressine  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 10
  • Joined: 18-December 08

Treeview checkbox problem

Posted 18 December 2008 - 08:29 PM

Hi,

I'm trying to do treeview checkbox function in Visual Studio 2005 using VB.Net. I have successfully loaded the treeview checkbox as you can see in my attachment. But the problem starts here. I have designed the form before I inserted any code inside of it so my programming is mainly trying to connect to the instance in the design.

This are the following function I want to perform on the treeview checkbox:

1. When I select the ITAD checkbox, all the nodes under it will be checked automatically
2. When I select the Raw checkbox, all node under it will be selected.

When I search the internet on how to do this, I cannot understand most of them. Mainly because I'm new at this programming practice. So, I'm asking for any guidance on how to do this. :stupid:

Any contribution and assistance is greatly appreciated. :^:

Thanks

Attached image(s)

  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: Treeview checkbox problem

#2 kasbaba  Icon User is offline

  • D.I.C Head

Reputation: 28
  • View blog
  • Posts: 133
  • Joined: 03-November 08

Re: Treeview checkbox problem

Posted 19 December 2008 - 10:56 AM

Hi,

I am not very good at Treeviews either, however I created this code. Check it and let me know if this works for you.


    Private Sub TreeView1_AfterCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterCheck
        If e.Node.Checked = True Then
            CheckNode(e.Node.Nodes)
        Else
            UnCheckNode(e.Node.Nodes)
        End If
    End Sub

    Public Function CheckNode(ByVal _nodeCollection As TreeNodeCollection) As TreeNode
        Dim tmpNode As TreeNode
        For Each _child As TreeNode In _nodeCollection
            _child.Checked = True
            tmpNode = CheckNode(_child.Nodes)
            If Not tmpNode Is Nothing Then
                Return tmpNode
            End If
        Next
        Return Nothing
    End Function

    Public Function UnCheckNode(ByVal _nodeCollection As TreeNodeCollection) As TreeNode
        Dim tmpNode As TreeNode
        For Each _child As TreeNode In _nodeCollection
            _child.Checked = False
            tmpNode = UnCheckNode(_child.Nodes)
            If Not tmpNode Is Nothing Then
                Return tmpNode
            End If
        Next
        Return Nothing
    End Function


Hope this helps.

kasbaba
Was This Post Helpful? 0
  • +
  • -

#5 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Treeview checkbox problem

Posted 19 December 2008 - 01:04 PM

There are a couple ways to handle this situation, I will show both. The first (and probably my choice) would be to create a procedure that checks the status of the parent node and loop through each child node checking or unchecking them based on the status of the parent node. You can then call this procedure in the AfterCheck Event of the TreeView

Private Sub HandleChildNodeCheckedState(ByRef currentNode As TreeNode)
	Dim checkedStatus As Boolean = currentNode.Checked
	For Each childNode As TreeNode In currentNode.Nodes
		childNode.Checked = checkedStatus
		CheckChildNode(node)
	Next
End Sub

Private Sub myTree_AfterCheck(ByRef sender As Object, ByRef e As TreeViewEventArgs) Handles MyTree.AfterCheck
	HandleChildNodeCheckedState(e.Node)
End Sub



The second is to just handle it all in the [b]AfterCheck Event[/url], like this

Private Sub myTree_AfterCheck(ByRef sender As Object, ByRef e As TreeViewEventArgs) Handles MyTree.AfterCheck
	Dim currentNode As TreeNode
	For Each currentNode In e.Node.Nodes
		currentNode.Checked = e.Node.Checked
	Next
End Sub



I prefer the first way because it also un-checks the child nodes if the parent is un-checked. Hope this helps :)
Was This Post Helpful? 2

#6 Stressine  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 10
  • Joined: 18-December 08

Re: Treeview checkbox problem

Posted 22 December 2008 - 12:54 AM

I've got it running now. Thank you all for your help.
Was This Post Helpful? 1

#7 nav234  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 04-December 09

Re: Treeview checkbox problem

Posted 04 December 2009 - 12:25 AM

Hi,
I need to select many checkboxes in a Tree view,which are
retrived from Database.
My project is windows based and using WPf.

Can anyone help on this issue ???

Thanks in advance

Regards

naveen... ;)
Was This Post Helpful? 0
  • +
  • -

#8 motcom  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 290
  • View blog
  • Posts: 1,371
  • Joined: 16-June 08

Re: Treeview checkbox problem

Posted 04 December 2009 - 01:31 AM

Hi,

You are in the wrong forum

Here is the WPF forum
http://www.dreaminco...howforum121.htm

Also you should start your own post and not add to existing ones (if you have a question)

Also Please read the forum rules
Was This Post Helpful? 0
  • +
  • -

#9 Guest_Prakash jha*


Reputation:

Re: Treeview checkbox problem

Posted 10 May 2010 - 04:49 AM

COOl Post!
Was This Post Helpful? 0

#10 Guest_Arnold*


Reputation:

Re: Treeview checkbox problem

Posted 03 January 2011 - 01:59 PM

leaving of the image thumbnail(s), as it would be to select the node Father when be a node.filho selected???

example

in case it be selected of the checkbox son, the checkbox father to be selected to be selected

excuse the mistakes in the writing, because I am Brazilian and phallus very badly English
Was This Post Helpful? 0

Page 1 of 1