Skip to main content
Home Forums Silverlight Programming Silverlight Controls and Silverlight Toolkit Adding Checkbox in Treeview Control....
10 replies. Latest Post by DJanjicek on August 15, 2009.
(0)
sureshch...
Member
0 points
1 Posts
05-12-2009 4:31 AM |
Hi,
I am looking for a source code to add a check box in a treeview control and when selected in one of the parent node it has to select all the child nodes and vice versa.
varshavmane
Contributor
6263 points
1,489 Posts
05-12-2009 11:04 AM |
You can have a look at this link:
http://silverlight.net/blogs/justinangel/archive/2008/11/18/silverlight-toolkit-treeview-treeviewitem-amp-hierarchaldatatemplate.aspx
or you can do something like this:
Parent.Header = "Parent";...if(Child1.Items.Count > 0) Child1.Header = "Child1";else Child1.Header = new CheckBox();
do looping for treeview control to make all the child nodes checked.
Hope this helps you.
Please "Mark as Answer" if this post answered your question. :)
JustinAngel
4415 points
596 Posts
05-12-2009 2:30 PM |
I strongly recommend you read my TreeView article previously linked here. Basically, You'll need to have a CheckBox databound to some value in a HierarchicalDataTemplate.
We've got a sample for that up on our official Silverlight Toolkit samples: http://silverlight.net/samples/sl2/toolkitcontrolsamples/run/default.html?path=Controls|TreeView|Using%20CheckBoxes
Telos
67 points
43 Posts
07-01-2009 2:17 AM |
I'm also trying to achieve this but my datacontext items don't have a value which I could bind to my checkbox. I want to do another stuff when the checkbox is clicked. Everything else is working for me but I can't seem to find the checkbox control within the TreeViewItem. Do I need to find a way to bind the checkbox to a value or is there a way to find the Checkbox control within the treeviewitem?
07-01-2009 2:30 AM |
You can try something:
TreeViewItem
CheckBox chk = (CheckBox)newParent.Header;
HTH
07-01-2009 2:50 AM |
This didn't work. I have the datacontext item in the Header, no checkbox. I have a datatemplate with a stackpanel and a checkbox and contentpresenter inside it.
07-01-2009 3:18 AM |
I think what Justin Angel suggested will help you.
07-02-2009 2:56 AM |
Yes, that helped. I'm using RIA Services but I extended the EF model class with a custom property and got it binded for the checbox. Now everything works fine. Thanks again.
07-02-2009 3:02 AM |
My pleasure
usamakhan86
8 points
7 Posts
08-15-2009 4:27 AM |
try this http://usamawahabkhan.blogspot.com/2009/07/treeview-checkbox-databinding.html
DJanjicek
Participant
964 points
319 Posts
08-15-2009 4:50 AM |
You could also use the TreeView control from VectorLight http://www.vectorlight.net/controls/tree_view.aspx
It has some very useful features, and also the ones you mentioned....