On the Page, I add UserControl into GridView dynamically. So, each UserControl can contain different kind of controls ( TextBox, CheckBox, Radio Button)
How to get a collection of control of textbox using VisualTreeHelper and check which textBox is empty.
I found a code similiar to this problem and modified it but not working.
I dont know what this means in the code and if it is required?
list.AddRange(AllTextBoxes(child))
Should I use MyList.Select() or MyList.Where() ?
For example , the name of UserControl is : UserForm. This will be added into the GridView on the current page
Thanks
void FindTextBoxes()
{
List <TextBox> MyList = AllTextBoxes(UserForm);
var count = MyList.Where(x= > if(string.IsEmptyOrNull(x.Text));
}
List <TextBox> AllTextBoxes(DependencyObject parent)
{
var list = new List <TextBox>();
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++)
{
var child = VisualTreeHelper.GetChild(parent, i);
if (child is TextBox)
list.Add(child as TextBox);
list.AddRange(AllTextBoxes(child));
}
return list;
}