|
-
Nov 4th, 2006, 05:00 AM
#1
Thread Starter
Hyperactive Member
[2005] Loop Tp Clear Controls In A SplitContainer
How to you clear values in controls in a SplitContainer using a loop?
Anyone tried it!
-
Nov 4th, 2006, 05:05 AM
#2
Re: [2005] Loop Tp Clear Controls In A SplitContainer
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.
-
Nov 4th, 2006, 05:19 AM
#3
Re: [2005] Loop Tp Clear Controls In A SplitContainer
Try this
VB Code:
Me.SplitContainer1.Panel1.Controls.Clear()
Me.SplitContainer1.Panel2.Controls.Clear()
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Nov 4th, 2006, 05:28 AM
#4
Thread Starter
Hyperactive Member
Re: [2005] Loop Tp Clear Controls In A SplitContainer
Thanks, but in a loop to clear the common windows forms controls.
-
Nov 4th, 2006, 05:32 AM
#5
Thread Starter
Hyperactive Member
Re: [2005] Loop Tp Clear Controls In A SplitContainer
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
-
Nov 4th, 2006, 05:34 AM
#6
Thread Starter
Hyperactive Member
Re: [2005] Loop Tp Clear Controls In A SplitContainer
shakti5385, your control does not work too, if the controls are in a splitContainer.
-
Nov 4th, 2006, 05:34 AM
#7
Re: [2005] Loop Tp Clear Controls In A SplitContainer
VB Code:
Dim ctrl As Control = myForm.GetNextControl(myForm, True)
This will not look for controls within Containers
Last edited by ComputerJy; Nov 4th, 2006 at 05:40 AM.
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Nov 4th, 2006, 05:49 AM
#8
Thread Starter
Hyperactive Member
Re: [2005] Loop Tp Clear Controls In A SplitContainer
so....is there a way through container controls?
-
Nov 4th, 2006, 06:09 AM
#9
Re: [2005] Loop Tp Clear Controls In A SplitContainer
 Originally Posted by maps
shakti5385, your control does not work too, if the controls are in a splitContainer.
Ok I will check It. Thanks
-
Nov 4th, 2006, 06:16 AM
#10
Re: [2005] Loop Tp Clear Controls In A SplitContainer
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
-
Nov 4th, 2006, 07:09 AM
#11
Thread Starter
Hyperactive Member
Re: [2005] Loop Tp Clear Controls In A SplitContainer
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.
-
Nov 4th, 2006, 09:47 AM
#12
Thread Starter
Hyperactive Member
Re: [2005] Loop Tp Clear Controls In A SplitContainer
-
Nov 4th, 2006, 09:58 AM
#13
Addicted Member
Re: [2005] Loop Tp Clear Controls In A SplitContainer
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
-
Nov 5th, 2006, 06:37 AM
#14
Thread Starter
Hyperactive Member
Re: [2005] Loop Tp Clear Controls In A SplitContainer
Thanks WayneSpangler, that does the trick.
But this needs to be
Dim ctrl As Control = SplitContainer1.GetNextControl(SplitContainer1, True)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|