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

[Solved] Programmatically disable check boxes on some nodes

5 Answers 560 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Mark Ryall
Top achievements
Rank 1
Mark Ryall asked on 28 Jan 2009, 01:45 AM
Despite the documentation attached to the property, the RadTreeViewItem.IsCheckBoxEnabled property is readonly.

On a dialog prior presented to users generating a report, we want to be able to allow users to select from a hierarchical data structure the nodes to include.

We want to preselect a number of tree nodes, disallow users from changing the checked state of those nodes but allow users to check/uncheck the rest of the nodes.

This would be slightly complex in that unchecking the parent node should not alter the checked state of these mandatory nodes.

Is there any way to achieve this with the built in check box functionality?

The alternative would be for us to put our own checkboxes in the item template but that seems a lot more work.

5 Answers, 1 is accepted

Sort by
0
Valentin.Stoychev
Telerik team
answered on 30 Jan 2009, 08:26 AM
Hi Mark Ryall,

You can use the PreviewChecked event to achieve this. Just provide the logic in the event handler based on the node clicked.

Please let us know if this works for you.

Best wishes,
Valentin.Stoychev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Jack
Top achievements
Rank 1
answered on 31 May 2009, 03:27 PM
Valentin,

Just to save me some time and effort upfront I was hoping you could expand a bit on the use of PreviewChecked and/or recommend a solution direction for me.

My use case is as follows:

Present a two tier treeview (databound to hier template) that displays a set of items I want the users to select.  I would use a list view and allow extended select but the list is long and has some grouping.  Thus I've implemented it as a tree.  Level One is the groups and level two is the actual items.

The tree works great with EnableCheckBoxes and EnableTriState.  I can pick/choose what I need and it is very efficient to select a group and then just unselect a couple of items.  Anyhow I now need to extend it a little bit and not let the users select certain tasks.  Think of it like a check-in/check-out process (SourceSafe Library) where some items will have already been checked out.  I need to show them in the list but I can't let the user select them.

I am okay with popping up a message at the treeview item level if I want to disallow/cancel the checking procedure but at the group level I want the 'checking' process to select all but the dis-allowed items.

I'm just curious if I can get any of this for free by disabling certain treeView items (is that possible) or if I need to provide logic for all the situations?  Idealy I would remove the checkbox from an individual item but it doesn't sound like that is possible.

Would it work to databind the 'checked' status?  If I could bind the checkbox to my BO then I could 'cancel' the checkbox selection by simply overriding the setter on my databound property based on the disabled flag.

Any other ideas or direction would be greatly appreciated.

Thanks

jack

0
Tihomir Petkov
Telerik team
answered on 03 Jun 2009, 04:43 PM
Hello Jack,

Please take a look at the attached project and let me know if it works for you. My solution may look a bit complex, but that is so because of the inner workings of the TriStateMode property which does not explicitly support your usage scenario. Anyways, I believe the attached project demonstrates the behavior you want. Let me know if it helps.

Sincerely yours,
Tihomir Petkov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Jack
Top achievements
Rank 1
answered on 08 Jun 2009, 05:56 PM
Tihomir,

Thank you for the example - it was quite useful.  I need to alter it to override the child count (I want the child count to be the number of enabled treeview items but otherwise that is very helpful.

I had a follow-up question:

I found that checking off the checkbox on a parent node only triggered the checked event on the children if the node was expanded although it did postpone it and trigger the checked event once I opened it.  It was a bit of surprise though.  Is that the expected behaviour or is that a bug?

Interestingly enough, once expanded and collapsed, the children event clicks do fire.  So it is obviously related to the fact it has 'never' been expanded even though there are children.

Whatever my solution the workaround isn't hard - I either auto-expand it for the users on 'checking' the parent or I manually set the child data I'm setting on the childItem clicked event.

Thanks

jack
0
Tihomir Petkov
Telerik team
answered on 09 Jun 2009, 01:33 PM
Hello Jack,

I'm glad the approach I suggested helped you. As for your question regarding the Checked event - this behavior is by design. When you data bind a treeview, the control knows about its items the way you supply them - usually business objects. Now, business objects, in most cases, do not have an IsChecked property and Checked event. So, the first time when an item needs to be rendered, the treeview dynamically generates a wrapper RadTreeViewItem around your business object and maps whatever you have specified in styles and templates. Therefore, before an item has been rendered, its wrapping RadTreeViewItem hasn't been generated and thus that item cannot throw the Checked event.

I hope I made things a bit clearer. Let me know if you have other questions.

Best wishes,
Tihomir Petkov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
TreeView
Asked by
Mark Ryall
Top achievements
Rank 1
Answers by
Valentin.Stoychev
Telerik team
Jack
Top achievements
Rank 1
Tihomir Petkov
Telerik team
Share this question
or