Programatically remove controls from a winform tab page


Author
Message
Michael R Poirier
Michael R Poirier
StrataFrame Beginner (13 reputation)StrataFrame Beginner (13 reputation)StrataFrame Beginner (13 reputation)StrataFrame Beginner (13 reputation)StrataFrame Beginner (13 reputation)StrataFrame Beginner (13 reputation)StrataFrame Beginner (13 reputation)StrataFrame Beginner (13 reputation)StrataFrame Beginner (13 reputation)
Group: StrataFrame Users
Posts: 9, Visits: 131
I have code that adds controls to a tab page - and the code below attempts to remove them.  All of the labels are removed - but the text boxes and combo boxes are not.  I even tried unbinding the text boxes and combo boxes - still not removed.

Any help is appreciated - code to remove controls:

Private Sub clearconditiontab()

Dim sftextbox As MicroFour.StrataFrame.UI.Windows.Forms.Textbox

Dim sfcombobox As MicroFour.StrataFrame.UI.Windows.Forms.ComboBox

For Each locontrol As Control In Me.TBP_Condition.Controls

If locontrol.GetType() Is GetType(MicroFour.StrataFrame.UI.Windows.Forms.ComboBox) Then

sfcombobox = locontrol

sfcombobox.BusinessObject = Nothing

sfcombobox.BindingField = Nothing

End If

If locontrol.GetType() Is GetType(MicroFour.StrataFrame.UI.Windows.Forms.Textbox) Then

sftextbox = locontrol

sftextbox.BusinessObject = Nothing

sftextbox.BindingField = Nothing

End If

Me.TBP_Condition.Controls.Remove(locontrol)

Next

Me.TBP_Condition.Refresh()

End Sub


Reply
Ivan George Borges
Ivan George Borges
Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)
Group: StrataFrame MVPs
Posts: 1.9K, Visits: 21K
I guess if you enumerate your controls, as soon as you remove one of them, the controls' indexex for all the others will change, which would cause the symptoms you are seeing. So, if you have index 0, 1, 2, 3, 4 and 5, as soon as you remove the 0 one, all the others decrease the value of 1, and each will become 0, 1, 2, 3 and 4. Then, moving to the next one would be the current 1, which was, formerly, the 2.
Maybe if you got the total number of controls first, and then went into a decreasing loop from the last to the first, all controls would be removed.
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Threaded View
Threaded View
Michael R Poirier - 16 Years Ago
Greg McGuffey - 16 Years Ago
Michael R Poirier - 16 Years Ago
Greg McGuffey - 16 Years Ago
Michael R Poirier - 16 Years Ago
                         Glad you go it working.
Greg McGuffey - 16 Years Ago
                             Here is my code ------------------------------------------- For Each...
- 14 Years Ago
                                 You are removing the items from the collection you are enumerating....
Trent L. Taylor - 14 Years Ago
                                 I guess if you enumerate your controls, as soon as you remove one of...
Ivan George Borges - 14 Years Ago

Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search