I need to remove at runtime a specified element of a Grid (grid1). This is the code where i add the elements.
examControls.Add(excontrol); // add the element on the ArrayList
excontrol.Margin = new Thickness(x, y + margin, 0, 0);
grid1.Children.Add(excontrol);
How can i remove at runtime a specified "excontrol" element (added at runtime) ?
Thanks in advance
If you keep a record of the control you can simply do:
grid1.Children.Remove(excontrol);
If you don't have a variable that holds the control you wish to remove you'll have to identify it in some way (Tag, Name), then find that control in the grid's children and then call Remove
.
grid1.Children.Remove(excontrol) //edited per your edit -- this is exactly what ChrisF posted though
or
grid1.Children.RemoveAt(index)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With