---
title: "Checkbox click copy texblocks in to a string list"  
description: "Checkbox click copy texblocks in to a string list"  
author: "Anonymous User"  
published: 2014-01-30  
updated: 2014-01-30  
canonical: https://www.mindstick.com/forum/1928/checkbox-click-copy-texblocks-in-to-a-string-list  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# Checkbox click copy texblocks in to a string list

In the HierarchicalDataTemplate, i got 2 textblocksand I want to [copy](https://www.mindstick.com/forum/161993/explain-the-numpy-array-copy-vs-view-with-example) the texts from the both. During the [check](https://yourviews.mindstick.com/story/2248/never-forget-to-check-these-specifications-before-buying-a-mobile-phone)-box [click](https://www.mindstick.com/articles/12423/social-login-magento-2-one-click-to-register-social)/check it'll [update](https://www.mindstick.com/forum/156353/what-is-hummingbird-update) the [text](https://www.mindstick.com/blog/301635/did-people-reinvent-texting-to-express-the-full-range-of-emotions) to a list.

The [function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) is getting the text from one textblock.

How can i get text from both textblocks and update it to the list?

```
private List<string> selectedNames = new List<string>();private void TreeView_Checked(object sender, RoutedEventArgs e){    CheckBox chkBox = sender as CheckBox;    StackPanel stackPanel = chkBox.Parent as StackPanel;    TextBlock txtBlock = FindVisualChild<TextBlock>(stackPanel);    bool isChecked = chkBox.IsChecked.HasValue ? chkBox.IsChecked.Value : false;    if (isChecked)    {        selectedNames.Add(txtBlock.Text );                }}
```

**[CheckBox](https://www.mindstick.com/articles/291/how-should-use-checkbox-control-in-vb-dot-net) get text function:**

```
private static T FindVisualChild<T>(DependencyObject obj) where T : DependencyObject{    for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)    {        DependencyObject child = VisualTreeHelper.GetChild(obj, i);        if (child != null && child is T)            return (T)child;        else        {            T childOfChild = FindVisualChild<T>(child);            if (childOfChild != null)                return childOfChild;        }    }    return null;}
```

## [WPF](https://www.mindstick.com/forum/304/wpf) HierarchicalDataTemplate:

```
<StackPanel Orientation="Horizontal" ><CheckBox Name="checkBoxTree"  Checked="TreeView_Checked" Unchecked="checkBoxTree_Unchecked"          Margin="0,4,0,0"  Style="{DynamicResource CheckBoxStyle1}"/><TextBlock Text="{Binding XPath=@Name, Mode=TwoWay}" /><TextBlock >                                         <Hyperlink NavigateUri="{Binding XPath=@WebSite}" RequestNavigate="Hyperlink_RequestNavigate">                <TextBlock Text="{Binding XPath=@WebSite}" />           </Hyperlink>   </TextBlock></StackPanel>
```

## Replies

### Reply by Pravesh Singh

Hi Ben,\
Try This:\

```
private void TreeView_Checked(object sender, RoutedEventArgs e){    CheckBox chkBox =sender as CheckBox;    StackPanel stackPanel = chkBox.Parent as StackPanel;    TextBlock txtBlock = FindVisualChild<TextBlock>(stackPanel);    Hyperlink hyperlink = FindVisualChild<Hyperlink>(stackPanel);    TextBlock secondTextBlock = FindVisualChild<TextBlock>(hyperlink);    bool isChecked = chkBox.IsChecked.HasValue ? chkBox.IsChecked.Value : false;    if (isChecked)    {         
selectedNames.Add(txtBlock.Text);  
       
selectedNames.Add(secondTextBlock.Text);               }       }
```


---

Original Source: https://www.mindstick.com/forum/1928/checkbox-click-copy-texblocks-in-to-a-string-list

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
