Checkbox cascade Selection in Treeview

Source: Internet
Author: User
1 private void Init () 2 {3 TreeViewItem tvi_0 = new TreeViewItem (); 4 5 CheckBox cb = new CheckBox (); 6 cb. content = "all"; 7 cb. checked + = new RoutedEventHandler (sender, e) =>{ foreach (TreeViewItem item in tvi_0.Items) {(item. header as StackPanel ). children [0] as CheckBox ). isChecked = true ;}}); 8 cb. unchecked + = new RoutedEventHandler (sender, e) =>{ foreach (TreeViewItem item in tvi_0.Items) {(item. header as StackPanel ). children [0] as CheckBox ). isChecked = false ;}}); 9 10 StackPanel sp = new StackPanel (); 11 sp. children. add (cb); 12 13 tvi_0.Name = "0"; 14 tvi_0.Header = sp; // The key is in this Header 15 tvi_0.IsExpanded = true; 16 17 treeview_1.Items.Add (tvi_0 ); 18 19 TreeViewItem tviTmp = null; 20 StackPanel sptmp = null; 21 CheckBox cbtmp = null; 22 for (int I = 0; I <10; I ++) 23 {24 tviTmp = new TreeViewItem (); 25 sptmp = new StackPanel (); 26 cbtmp = new CheckBox (); 27 28 tviTmp. name = "tviTmp" + I. toString (); 29 cbtmp. name = "cbtmp" + I. toString (); 30 sptmp. name = "sptmp" + I. toString (); 31 32 cbtmp. content = "CheckBox" + I. toString (); 33 sptmp. children. add (cbtmp); 34 tviTmp. header = sptmp; 35 tvi_0.Items.Add (tviTmp); 36} 37}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.