Skip to main content

Microsoft Silverlight

Answered Question Adding Checkbox in Treeview Control....RSS Feed

(0)

sureshchsahu
sureshch...

Member

Member

0 points

1 Posts

Adding Checkbox in Treeview Control....

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
varshavmane

Contributor

Contributor

6263 points

1,489 Posts

Answered Question

Re: Adding Checkbox in Treeview Control....

Hi,

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. :)

Please "Mark as Answer" if this post answered your question. :)
Visit my Blog: http://varshavmane.blogspot.com/

JustinAngel
JustinAngel

Contributor

Contributor

4415 points

596 Posts

Answered Question

Re: Adding Checkbox in Treeview Control....

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 

 

--
Justin Angel,
Blog @ http://silverlight.net/blogs/JustinAngel
Twitter @ http://twitter.com/JustinAngel

Telos
Telos

Member

Member

67 points

43 Posts

Re: Adding Checkbox in Treeview Control....

 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?

--
Antti Simonen

varshavmane
varshavmane

Contributor

Contributor

6263 points

1,489 Posts

Re: Re: Adding Checkbox in Treeview Control....

You can try something:

TreeViewItem newParent = (TreeViewItem)TreeView1.SelectedItem;

CheckBox chk = (CheckBox)newParent.Header;

HTH Smile

Please "Mark as Answer" if this post answered your question. :)
Visit my Blog: http://varshavmane.blogspot.com/

Telos
Telos

Member

Member

67 points

43 Posts

Re: Re: Adding Checkbox in Treeview Control....

 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.

--
Antti Simonen

varshavmane
varshavmane

Contributor

Contributor

6263 points

1,489 Posts

Re: Re: Re: Adding Checkbox in Treeview Control....

I think what Justin Angel suggested will help you.

Please "Mark as Answer" if this post answered your question. :)
Visit my Blog: http://varshavmane.blogspot.com/

Telos
Telos

Member

Member

67 points

43 Posts

Re: Re: Re: Adding Checkbox in Treeview Control....

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.

--
Antti Simonen

varshavmane
varshavmane

Contributor

Contributor

6263 points

1,489 Posts

Re: Re: Re: Re: Adding Checkbox in Treeview Control....

My pleasure Smile

Please "Mark as Answer" if this post answered your question. :)
Visit my Blog: http://varshavmane.blogspot.com/

usamakhan86
usamakhan86

Member

Member

8 points

7 Posts

Re: Re: Re: Re: Re: Adding Checkbox in Treeview Control....

try this http://usamawahabkhan.blogspot.com/2009/07/treeview-checkbox-databinding.html

DJanjicek
DJanjicek

Participant

Participant

964 points

319 Posts

Re: Re: Re: Re: Re: Adding Checkbox in Treeview Control....

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....

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities