Results 1 to 14 of 14

Thread: [2005] Loop Tp Clear Controls In A SplitContainer

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    [2005] Loop Tp Clear Controls In A SplitContainer

    How to you clear values in controls in a SplitContainer using a loop?
    Anyone tried it!

  2. #2
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Thumbs up 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.

  3. #3
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: [2005] Loop Tp Clear Controls In A SplitContainer

    Try this
    VB Code:
    1. Me.SplitContainer1.Panel1.Controls.Clear()
    2.         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

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Re: [2005] Loop Tp Clear Controls In A SplitContainer

    Thanks, but in a loop to clear the common windows forms controls.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    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:
    1. Public Sub ClearForm(ByVal myForm As Form)
    2.         'Gets the first control on the form(me) in the tab order(doesnt matter whether Tab Order is Set To False).
    3.         'Dim myForm As New Form
    4.         Dim ctrl As Control = myForm.GetNextControl(myForm, True)
    5.         Do Until ctrl Is Nothing
    6.             If TypeOf ctrl Is TextBox Then
    7.                 ctrl.Text = ""
    8.             ElseIf TypeOf ctrl Is ComboBox Then
    9.                 ctrl.Text = ""
    10.             End If
    11.             'Get the next control in the tab order.
    12.             ctrl = myForm.GetNextControl(ctrl, True)
    13.         Loop
    14.  
    15.     End Sub

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Re: [2005] Loop Tp Clear Controls In A SplitContainer

    shakti5385, your control does not work too, if the controls are in a splitContainer.

  7. #7
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: [2005] Loop Tp Clear Controls In A SplitContainer

    VB Code:
    1. 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

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Re: [2005] Loop Tp Clear Controls In A SplitContainer

    so....is there a way through container controls?

  9. #9
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: [2005] Loop Tp Clear Controls In A SplitContainer

    Quote Originally Posted by maps
    shakti5385, your control does not work too, if the controls are in a splitContainer.
    Ok I will check It. Thanks

  10. #10
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: [2005] Loop Tp Clear Controls In A SplitContainer

    You could try something like this:
    VB Code:
    1. Private Sub ClearChildControls(parent_control As IContainerControl)
    2.   For Each child_control As Control In parent_control
    3.     If (child_control.GetType().GetInterface("IContainerControl")) Then
    4.       ClearChildControls(child_control)
    5.     Else
    6.       If (TypeOf child_control Is TextBox) Then _
    7.         child_control.Text = String.Empty
    8.     End If
    9.   Next
    10. End Sub

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    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.

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Re: [2005] Loop Tp Clear Controls In A SplitContainer

    **Bump**

  13. #13
    Addicted Member
    Join Date
    Jan 2002
    Location
    West Virginia
    Posts
    193

    Re: [2005] Loop Tp Clear Controls In A SplitContainer

    Try this. Works for me.
    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         Dim ctrl As Control = SplitContainer1.GetNextControl(ctrl, True)
    3.         Do Until ctrl Is Nothing
    4.             If TypeOf ctrl Is TextBox Then
    5.                 ctrl.Text = ""
    6.             ElseIf TypeOf ctrl Is ComboBox Then
    7.                 ctrl.Text = ""
    8.             End If
    9.             'Get the next control in the tab order.
    10.             ctrl = SplitContainer1.GetNextControl(ctrl, True)
    11.         Loop
    12.  
    13.     End Sub

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    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
  •  



Click Here to Expand Forum to Full Width