Adding Checkbox in Treeview Control....
-
Tuesday, May 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.
All Replies
-
Tuesday, May 12, 2009 11:04 AM
Hi,
You can have a look at this link:
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. :)
-
Tuesday, May 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 -
Wednesday, July 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?
-
Wednesday, July 01, 2009 2:30 AM
You can try something:
TreeViewItem
newParent = (TreeViewItem)TreeView1.SelectedItem;CheckBox chk = (CheckBox)newParent.Header;
HTH

-
Wednesday, July 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.
-
Wednesday, July 01, 2009 3:18 AM
I think what Justin Angel suggested will help you.
-
Thursday, July 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.
-
Thursday, July 02, 2009 3:02 AM
My pleasure

-
Saturday, August 15, 2009 4:27 AM
try this http://usamawahabkhan.blogspot.com/2009/07/treeview-checkbox-databinding.html
-
Saturday, August 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....
-
Friday, May 21, 2010 2:55 AMTry this i hope it will help http://cid-f945c63857c2af06.skydrive.live.com/self.aspx/.Public/TreeView%20Ischecked%20Checkbox.rar
TreeViewItem Tvitem = new TreeViewItem(); CheckBox CbItem = new CheckBox(); CbItem.Checked += (a,b )=> { Checked(a); }; CbItem.Unchecked += (a,b )=> { Unchecked(a); }; StackPanel Spcpanel = new StackPanel(); CbItem.DataContext = //--data; CbItem.Name = Ldata.ObjectId.ToString(); CbItem.IsChecked = Ldata.Value; CbItem.Foreground = new SolidColorBrush(Colors.Black); Image LSymbol = new Image(); BitmapImage LSymbolsource = new BitmapImage(new Uri(App_Codes.ApplicationConfig.AbsoluteImagePath + Ldata.SymbolRef + ".png", UriKind.Absolute)); LSymbol.Width = 16; LSymbol.Height = 16; LSymbol.Source = LSymbolsource; Spcpanel.Orientation = Orientation.Horizontal; Spcpanel.Children.Add(new Label() { Content = LSymbol,Margin = new Thickness(0,0,4,0) }); Spcpanel.Children.Add(new Label(){Content= Ldata.Name}); CbItem.Content = Spcpanel; Tvitem.Header = (CbItem); return Tvitem;
-
Tuesday, October 26, 2010 3:27 AM
Hi,
My Problem is similar to yours (That you had earlier), i am unable to add check box in silverlight-4 tree view control. Do i need to add something from xaml because i am loading my tree from .cs. It would be great help if you can share small part of code..
Thank You in Advance
-
Tuesday, October 26, 2010 5:40 AM

