Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove specified Children element of a Grid

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

like image 881
Nicolò Carpignoli Avatar asked Mar 25 '13 17:03

Nicolò Carpignoli


2 Answers

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.

like image 147
ChrisF Avatar answered Nov 10 '22 14:11

ChrisF


grid1.Children.Remove(excontrol) //edited per your edit -- this is exactly what ChrisF posted though

or

grid1.Children.RemoveAt(index)
like image 21
tnw Avatar answered Nov 10 '22 13:11

tnw