I am having checkbox inside listview . i want to refer the checkbox from button click event
i tried this code
CheckBox myTextbox = GetTemplateChild("chb_standard") as CheckBox;
CheckBox myTextBlock = (CheckBox)this.FindName("chb_standard");
it will return only a null object
i also tried find visual child format
private childItem FindVisualChild<childItem>(DependencyObject obj)
where childItem : DependencyObject
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)
{
DependencyObject child = VisualTreeHelper.GetChild(obj, i);
if (child != null && child is childItem)
return (childItem)child;
else
{
childItem childOfChild = FindVisualChild<childItem>(child);
if (childOfChild != null)
return childOfChild;
}
}
return null;
}
for (int k = 0; k <= listView1.Items.Count - 1; k++)
{
ListViewData lvc = (ListViewData)listView1.Items[k];
//var chb_standard = sender as CheckBox;
ListViewItem ListBoxItemObj =(ListViewItem)listView1.ItemContainerGenerator.ContainerFromItem(listView1.Items[k]);
//bool check = ListBoxItemObj.HasContent;
// find a ContentPresenter of that list item.. [Call FindVisualChild Method]
ContentPresenter ContentPresenterObj = FindVisualChild<ContentPresenter>(ListBoxItemObj);
// call FindName on the DataTemplate of that ContentPresenter
DataTemplate DataTemplateObj = ContentPresenterObj.ContentTemplate;
CheckBox Chk = (CheckBox)DataTemplateObj.FindName("chb_standard", ContentPresenterObj);
Chk.IsChecked = true;
}
ListBoxItemObj will return always null actually i am having values in listview
so is there another method to refer the checkbox send some code example or link