Hi,
I'm trying to write a general function to simply clear a collection of
fields from both a group box and a tab control. Here is what I want my code
to look like:
private void ClearFields(GroupBox groupbox)
{
ClearFields((ControlCollection)groupbox.Controls);
}
private void ClearFields(TabPage pg)
{
ClearFields((ControlCollection)pg.Controls);
}
private void ClearFields(ControlCollection lst)
{
foreach (Control c in lst)
{
if (c.GetType() != typeof(System.Windows.Forms.Button))
{
c.Text = "";
}
}
}
}
However, when I write my code this way I get a runtime error that says I
cannot convert the type TabPageControlCollection to a ControlCollection.
TabPageControlCollection is a derived class of ControlCollection. What is it
that I'm not understanding about casting?