Results 1 to 4 of 4

Thread: [Resolved]Help in VB 2005

Hybrid View

  1. #1

    Thread Starter
    Lively Member sinchan's Avatar
    Join Date
    Feb 2004
    Location
    UK
    Posts
    106

    Resolved [Resolved]Help in VB 2005

    I am very new at VB 2005. I used to clear my TextBoxes on the form by using following code in VB6.

    I call a procedure from Module named ResetForm

    VB Code:
    1. Sub ResetForm()
    2.      DIM CTRL as Control
    3.      For Each CTRL in Me.Controls
    4.           If TypeOf CTRL Is TextBox then _
    5.                CTRL=vbNullString
    6.      Next
    7. End Sub

    I have used more than one GroupPanel on the form. Whenever I debug the program, It does not go to the control which are in the GroupPanel.

    I want to check each control in each GroupPanel.

    So, please help me out....
    Last edited by sinchan; Nov 23rd, 2006 at 02:06 AM.
    i love VB more than BV(means wife in our language)

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Help in VB 2005

    If you have a VB.NET question you should post it in the VB.NET forum, although the same principle would apply in other .NET languages in this case. There are a couple of ways to achieve your aim and they've both been posted several times. Controls in a container, like a GroupBox, are not on the form itself so they are not in the form's Controls collection. They are in the container's Controls collection. You can visit every control on a form using recursion:
    VB Code:
    1. Private Sub ClearTextBoxes(ByVal container As Control)
    2.     For Each ctl As Control In container.Controls
    3.         If TypeOf ctl Is TextBox Then
    4.             ctl.ResetText()
    5.         Else If ctl.Controls.Count > 0 Then
    6.             Me.ClearTextBoxes(ctl)
    7.         End If
    8.     Next ctl
    9. End Sub
    or you can use the GetNextControl method to do it without explicit recursion. I've posted code in the VB.NET CodeBank to do that.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Addicted Member craigreilly's Avatar
    Join Date
    Jul 2004
    Location
    Scottsdale, AZ
    Posts
    188

    Re: Help in VB 2005

    Great question. Here is some additional code to clear other controls
    VB Code:
    1. Private Sub ClearForm(ByVal container As Control)
    2.         For Each ctl As Control In container.Controls
    3.             If TypeOf ctl Is TextBox Then
    4.                 DirectCast(ctl, TextBox).ResetText()
    5.             ElseIf TypeOf ctl Is CheckBox Then
    6.                 DirectCast(ctl, CheckBox).Checked = False
    7.             ElseIf TypeOf ctl Is RadioButton Then
    8.                 DirectCast(ctl, RadioButton).Checked = False
    9.             ElseIf TypeOf ctl Is ComboBox Then
    10.                 DirectCast(ctl, ComboBox).Items.Clear()
    11.             ElseIf TypeOf ctl Is ListView Then
    12.                 DirectCast(ctl, ListView).Items.Clear()
    13.             ElseIf ctl.Controls.Count > 0 Then
    14.                 Me.ClearForm(ctl) 'This handles the GroupBoxes
    15.             End If
    16.         Next ctl
    17. End Sub

    Then, to clear the form, use

    VB Code:
    1. ClearForm(me)
    VB 6 / VB.NET 2003, 2005 / Crystal Reports 9-12

  4. #4

    Thread Starter
    Lively Member sinchan's Avatar
    Join Date
    Feb 2004
    Location
    UK
    Posts
    106

    Talking Re: Help in VB 2005

    Thank u guys! Here u got a reputation from me

    Thanks a lot

    i love VB more than BV(means wife in our language)

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