开发者

Can't set Checked property of a TreeNode in the AfterCheck event

开发者 https://www.devze.com 2023-03-08 08:38 出处:网络
I have a simple TreeView (several parents and 1 level of children each) in C# 2008 (.Net 3.5) on Vista.

I have a simple TreeView (several parents and 1 level of children each) in C# 2008 (.Net 3.5) on Vista.

In the AFterCheck routine I am attempting to set/unset the Checked property of the child nodes based on the state of the parent when it is clicked with the mouse.

Using MessageBoxes, I can see the event routine entered and the loop through the child nodes and if the parent is checked, the code

childnode.Checked = parentNode.Checked;

shows via the MessageBox.Show(childnode.Checked + " " + parentNode.Checked); following the execution of the code shows "False True" and the child checkbox remains unchecked in the TreeView.

I have tried several variations found on the web with the same result. I even tried a replacement TreeView (MWControls) with exactly the same results.

Interestingly, any other childnode property (say BackColor) I set takes effect.

I believe that recursion is not an issue and seems to be verified by the debugging MessageBoxes.

Any ideas?

Regards, Jim


This is a winform application.

I removed all of the MessageBox calls with no change; child nodes still not checked in response to the parent being checked.

I removed my AfterCheck routine and used the one referenced verbatum with the same results; child nodes not checked in response to t开发者_如何学运维he parent being checked.

I have played with this for hours with no luck.

The strange thing is that any other property I change (like BackColor) takes effect.

I did see an obscure reference on the web to this being a issue in Win7 but I can't find it again. Anyway, I am using Vista, .Net 3.5, and C# Express 2008.

Thanks for the input.

Regards, Jim


This example does what you need. Most likely your code isn't working because setting the child's Checked property is propogating the event again, and you're not checking for the Unknown action as the linked-to code does.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号