How to you clear values in controls in a SplitContainer using a loop?
Anyone tried it!
Printable View
How to you clear values in controls in a SplitContainer using a loop?
Anyone tried it!
Did not use the spliter control but I make a user control that clear all the data on the form, Check it at my signature user control for clear all form control. :wave:
Try this
VB Code:
Me.SplitContainer1.Panel1.Controls.Clear() Me.SplitContainer1.Panel2.Controls.Clear()
Thanks, but in a loop to clear the common windows forms controls.
i have been using the code below but it doesn't work when the controls are in a splitContainer. How can this be modified.
VB Code:
Public Sub ClearForm(ByVal myForm As Form) 'Gets the first control on the form(me) in the tab order(doesnt matter whether Tab Order is Set To False). 'Dim myForm As New Form Dim ctrl As Control = myForm.GetNextControl(myForm, True) Do Until ctrl Is Nothing If TypeOf ctrl Is TextBox Then ctrl.Text = "" ElseIf TypeOf ctrl Is ComboBox Then ctrl.Text = "" End If 'Get the next control in the tab order. ctrl = myForm.GetNextControl(ctrl, True) Loop End Sub
shakti5385, your control does not work too, if the controls are in a splitContainer.
This will not look for controls within ContainersQuote:
VB Code:
Dim ctrl As Control = myForm.GetNextControl(myForm, True)
so....is there a way through container controls?
Ok I will check It. ThanksQuote:
Originally Posted by maps
You could try something like this:
VB Code:
Private Sub ClearChildControls(parent_control As IContainerControl) For Each child_control As Control In parent_control If (child_control.GetType().GetInterface("IContainerControl")) Then ClearChildControls(child_control) Else If (TypeOf child_control Is TextBox) Then _ child_control.Text = String.Empty End If Next End Sub
Thanks, but there is an error on the for each statement...at parent_control
Expression is of type System.Windows.forms.IContainerControl which is not a collectiontype.
**Bump**
Try this. Works for me.
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim ctrl As Control = SplitContainer1.GetNextControl(ctrl, True) Do Until ctrl Is Nothing If TypeOf ctrl Is TextBox Then ctrl.Text = "" ElseIf TypeOf ctrl Is ComboBox Then ctrl.Text = "" End If 'Get the next control in the tab order. ctrl = SplitContainer1.GetNextControl(ctrl, True) Loop End Sub
Thanks WayneSpangler, that does the trick.
But this needs to be
Dim ctrl As Control = SplitContainer1.GetNextControl(SplitContainer1, True)