Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove Specific Type of Children from Grid Control

I want to remove a suppose control whose type is of border, from the grid control. how can I achieve it in WPF C# ?

Sorry Guys, My problem is that I have grid control which has GUI design at XAML end and user control which are added using C# and the some controls are overlapped. Some controls are removed but some are left which overlap one another. How can I remove all controls. The code you have posted work for control which are not overlapped but for overlapped ones, it didn't work.

like image 279
Asim Sajjad Avatar asked Dec 06 '25 06:12

Asim Sajjad


1 Answers

Here is my code:

 int intTotalChildren = grdGrid.Children.Count-1;
            for (int intCounter = intTotalChildren; intCounter > 0; intCounter--)
            {
                if (grdGrid.Children[intCounter].GetType() == typeof(Border))
                {
                    Border ucCurrentChild = (Border)grdGrid.Children[intCounter];
                    grdGrid.Children.Remove(ucCurrentChild);
                }                
            }

My error was that each time I used the Children.Count in the for loop and every time I removed a child, the Children.Count changed and not all children were removed.

like image 169
Asim Sajjad Avatar answered Dec 09 '25 03:12

Asim Sajjad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!