|
-
Nov 22nd, 2006, 03:24 AM
#1
Thread Starter
Lively Member
[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:
Sub ResetForm()
DIM CTRL as Control
For Each CTRL in Me.Controls
If TypeOf CTRL Is TextBox then _
CTRL=vbNullString
Next
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)
-
Nov 22nd, 2006, 07:24 AM
#2
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:
Private Sub ClearTextBoxes(ByVal container As Control)
For Each ctl As Control In container.Controls
If TypeOf ctl Is TextBox Then
ctl.ResetText()
Else If ctl.Controls.Count > 0 Then
Me.ClearTextBoxes(ctl)
End If
Next ctl
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.
-
Nov 22nd, 2006, 11:27 AM
#3
Addicted Member
Re: Help in VB 2005
Great question. Here is some additional code to clear other controls
VB Code:
Private Sub ClearForm(ByVal container As Control)
For Each ctl As Control In container.Controls
If TypeOf ctl Is TextBox Then
DirectCast(ctl, TextBox).ResetText()
ElseIf TypeOf ctl Is CheckBox Then
DirectCast(ctl, CheckBox).Checked = False
ElseIf TypeOf ctl Is RadioButton Then
DirectCast(ctl, RadioButton).Checked = False
ElseIf TypeOf ctl Is ComboBox Then
DirectCast(ctl, ComboBox).Items.Clear()
ElseIf TypeOf ctl Is ListView Then
DirectCast(ctl, ListView).Items.Clear()
ElseIf ctl.Controls.Count > 0 Then
Me.ClearForm(ctl) 'This handles the GroupBoxes
End If
Next ctl
End Sub
Then, to clear the form, use
VB 6 / VB.NET 2003, 2005 / Crystal Reports 9-12
-
Nov 23rd, 2006, 02:05 AM
#4
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|