-
October 26th, 2013, 06:14 PM
#1
Referencing controls in list
Hello,
I created a custom control (ErrorButton). When the main form loads i add some ErrorButtons to the controls collection and inside a list.
Code:
List<ErrorButton> errorButtonList = new List<ErrorButton>();
while (...)
{
ErrorButton eb = new ErrorButton();
// doing stuff
this.Controls.Add(eb);
errorButtonList.Add(eb);
}
But i don't want to reset them like this.
Code:
foreach (Control c in this.Controls)
{
if (c is ErrorButton)
{
ErrorButton er = (ErrorButton)c;
er.Reset();
}
}
I want to reset them like this.
Code:
foreach (ErrorButton er in errorButtonList)
{
er.Reset();
}
But it doesn't work. I thought the ErrorButtons are referenced inside the list, so any changes will change the ErrorButtons inside the form collection.
-
October 27th, 2013, 04:57 AM
#2
Re: Referencing controls in list
Try in this way
Code:
foreach (ErrorButton er in this.Controls.OfType<ErrorButton>())
{
er.Reset();
}
-
October 27th, 2013, 10:01 AM
#3
Re: Referencing controls in list
Yes it works, thanks Reroto.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|