Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Enumerating controls
Message
From
18/02/2009 10:54:06
John Baird
Coatesville, Pennsylvania, United States
 
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01382619
Message ID:
01382640
Views:
53
>Hi All, I have these two methods in the base class of my usercontrol which clear all data for certain controls, all works tickety boo except for the DataGridView section which is never hit on - in one of my uc's I have two DataGridView controls which are children of a groupbox - any idea why this doesn't work ?
>
>
>
>public virtual void ClearData()
>{
>            foreach (Control c in this.Controls)
>                this.ClearControl(c);
>            
>}
>
>
>private void ClearControl(Control c)
>{
>          if (c.Controls.Count > 0)
>                for (int i = 0; i < c.Controls.Count; i++)
>                    ClearControl(c.Controls[i]);
>            else
>            {
>                if (c is TextBox)
>                {
>                    TextBox tb = (TextBox)c;
>                    tb.Text = "";
>                }
>
>                if (c is CheckBox)
>                {
>                    CheckBox chk = (CheckBox)c;
>                    chk.Checked = false;
>                }
>
>                if (c is ListView)
>                {
>                    ListView lv = (ListView)c;
>                    lv.Items.Clear();
>                }
>
>                if (c is DataGridView)
>                {
>                    DataGridView dgv = (DataGridView)c;
>                    dgv.Rows.Clear();
>                }
>            }
>}
>
The groupbox is a container control in itself. You'll probably need to iterate the GroupBox.Controls collection also.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform