I have dynamically generated controls on the panels of windows form and i have also generated a button for removing the controls, all in rows.
int c = 0;
pri
Since the controls are added at the run time, register them before using the findName method using the register method.
StackPanel sp = new StackPanel
{
Name = "mySP",
Orientation = Orientation.Horizontal,
};
//need to register the control to find it by name
RegisterName(sp.Name, sp);
//now to find control by name
StackPanel sp = (StackPanel)mainStackPanel.FindName("mySP");
//deleting the control found
mainStackPanel.Children.Remove(sp);
//if you need to use the same name again, you have to unregister too
UnregisterName(sp.Name);