This is a migrated thread and some comments may be shown as answers.

TreeviewItem CheckState help

1 Answer 30 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
John Benson
Top achievements
Rank 1
John Benson asked on 22 Mar 2010, 03:00 PM
I am trying to create logic so that, based on a Boolean value, the user will be unable to "click" a TreeviewItem's check box. Unfortunately, I'm getting all kinds of unexpected behavior.

Based on some logic (seeing if this Boolean is set to true and seeing the number of selected items), I have an If statement in Treeview_Checked set the TreeviewItem.CheckState to Automation.ToggleState.Off. This works, and then runs through the Treeview_Unchecked code.

I let the program run until the very last bit of the "Treeview_Checked" snippet where the  e.Source.CheckState is still set to Off. However, as soon as I get back to the GUI interface the checkbox does have a check in it.

I can't see where this is being set and how I can interrupt it. I tried using the PreviewCheck and PreviewUnchecked events, but neither made a difference.

I'm using v2009.3.1219.1030 version as the latest release causes other parts of my code to function incorrectly, and would like to be able to stay with the version I am currently using.

Any suggestions on how I can get the functionality I'm look for? Thanks in advance.

UPDATE:

We decided to go with a different approach. We wiped out the list and then repopulated it with the newly selected item. Thanks to David for getting the creative juices flowing!

1 Answer, 1 is accepted

Sort by
0
David Brubacher
Top achievements
Rank 1
answered on 22 Mar 2010, 06:20 PM
I have the same application requirements, but I hid the checkbox if the user can't check it, so I don't care what state it's in.
I also modified the control template so the space for the checkbox remained despite it being hidden.

Looks good and works well

HTH
Tags
TreeView
Asked by
John Benson
Top achievements
Rank 1
Answers by
David Brubacher
Top achievements
Rank 1
Share this question
or