We help IT Professionals succeed at work.

How to Retain the check box value in Treeview control

sarankrishna
sarankrishna asked
on
I wanted to Retain the same value of the check box in a Treeview control when i click the check box of the node.

what i had did is

Private Sub tvwCompStruc_NodeCheck(ByVal Node As MSComctlLib.Node)
  Node.Checked = Not Node.Checked

End Sub

But the chekbox value is getting changed(I mean checking on and off is happening) while i click the check box of a node.



Comment
Watch Question

Ryan ChongSoftware Tead Lead / Business Analyst / System Analyst / Data Engineer
SILVER EXPERT

Commented:
Hi sarankrishna,

Private Sub TreeView_NodeCheck(ByVal Node As MSComctlLib.Node)
    Node.Checked = Not Node.Checked
End Sub

is No problem at all..

Maybe you can check your code in NodeClick or Click Envent of Tree View control to ensure the Checked value is not changing..

regards.
Senior Consultant
SILVER EXPERT
Most Valuable Expert 2011
Top Expert 2013
Commented:
Check boxes sometines work in wierd ways.  I am not familiar with the treeview check box but regular check boxes if you set them in code then the click event or check event occurs.

In your case you are
Private Sub tvwCompStruc_NodeCheck(ByVal Node As MSComctlLib.Node)
 Node.Checked = Not Node.Checked

End Sub

if you check the box the code unchecks it then it wants to check it.  With check boxes what I do is somwething like

Private Sub ck_ActivityAll_click()

  if ck_ActivityAll = vbunchecked then
     ck_ActivityAll = vbchecked
  endif

End Sub

This way since the user is clicking to turn it on (in my applications he is not allowed to turn it off by clicking) if he clicks it and turns it off then my code turns it back on.

Look into the way the check box works and the click or check events work for your application.

good luck
mlmcc
BRONZE EXPERT
Author of the Year 2009

Commented:
Hi sarankrishna,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept mlmcc's comment(s) as an answer.

sarankrishna, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
Per recommendation, force-accepted by
Netminder
Community Support Moderator

Explore More ContentExplore courses, solutions, and other research materials related to this topic.