Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Frnds,

can't clear the gridview values using clear button from MDI form:
C#
foreach (Control ct in cntr.Controls)
           {
               if (ct is TextBox)
               {
                   ((TextBox)ct).Clear();
               }
               else if (ct.HasChildren)
               {
                   ClearFields(ct);
               }
               else if (ct is ComboBox)
               {
                   ((ComboBox)ct).SelectedIndex = -1;
               }
               else if (ct is RichTextBox)
               {
                   ((RichTextBox)ct).Clear();
               }
               else if (ct is DataGridView)
               {
                   ((DataGridView)ct).Rows.Clear();
               }
           }
Posted
Updated 24-Feb-14 1:41am
v2
Comments
CHill60 24-Feb-14 7:44am    
Can you confirm that the textboxes, comboboxes etc ARE being cleared
johannesnestler 24-Feb-14 7:46am    
aha, are you shure the desired datagridview is contained in the controls collection (not nested, don't see any recursion or nesting nevel in your code)?
ZurdoDev 24-Feb-14 10:31am    
Just debug it and see what is happening.

1 solution

try this
datagridview1.Rows.Clear();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900