Reputation: 970
I have a TabControl
with three TextBoxes
that must all be populated. I'm aware there is a "sort of" method of selecting multiple controls of the same type in an overall form, however I was wondering if there was a simple way to select all the TextBoxes
within the TabControl
. Something similar to this pseudo-code:
void checkAllBoxes(object object)
{
using ((all of type TextBox) in TabControl)
{
if object.Text.HasValue;
DoSomething();
}
}
If not, why not?
Upvotes: 0
Views: 257
Reputation: 39966
Try this:
for (int i = 0; i < tabControl1.TabCount; i++)
{
foreach (TextBox textBox in tabControl1.TabPages[i].Controls.OfType<TextBox>().Cast<TextBox>())
{
textBox.Text = "";//or something else
}
}
Upvotes: 3
Reputation: 6967
You can filter the textboxes inside a tab page like this:
var txtList = tabControl1.TabPages[0].Controls.Cast<Control>()
.Where(c => c is TextBox)
.ToList();
Upvotes: 1