TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Sai Yang
NA
136
27.4k
How to clear control that has children?
Apr 12 2020 9:26 AM
hi there!
I want to clear control in child control. I use twice foreach loop, but the scond loop doesn't support with error like.
Error 1 foreach statement cannot operate on variables of type 'System.Windows.Forms.Control' because 'System.Windows.Forms.Control' does not contain a public definition for 'GetEnumerator'
F:\Programs\C#\AUTOSERVICE\AUTOSERVICE\Home.cs 141 25 AUTOSERVICE
I tried the code:
foreach (Control control in pnHome.Controls)
{
if (control is UserControl) // This control shown into a panel I give you code bellow. (This control is pnHome bellow)
{
if (control.HasChildren)
{
foreach (Control c in control) // this statement error as above
{
//I want to clear all control under myControl (See code bellow). (TextBox, CheckBox, Label, .. .etc )
}
}
}
}
Code to show UserControl to a Panel
myControl u = new myControl();
u.Dock = DockStyle.Fill;
pnHome.Controls.Clear();
pnHome.Controls.Add(u);
I don't know why?
Please, share help me to clear the control.
Thank you very much.
Reply
Answers (
1
)
C# listview header name=value from database
C# Listview one columns with two rows