I am clearing checkboxes using the code below I found written by someone on this site but it doesn't uncheck the checkboxes. Text box is working fine. My checkbox is on a groupbox control so would that make a difference -
Dim Ctrl As Control 'Declare generic control object
Dim MyCheckBox As CheckBox 'Declare CheckBox control object
For Each Ctrl In C.Controls
Select Case TypeName(Ctrl)
Case "TextBox" 'Do the following code if control is a Text Box
Ctrl.Text = ""
Case "CheckBox" 'Do the following code if control is a Check Box
MyCheckBox = CType(Ctrl, CheckBox) 'Use here as generic control type
MyCheckBox.Checked = False 'Ctrl doesn’t have Checked property
Case Else
' If Ctrl.Controls.Count > 0 Then 'Check for container control
' ClearAll(Ctrl) 'Recursively call sub for controls in container
'End If
End Select
Next Ctrl
Unchecking CheckboxesUnchecking Checkboxes in VB.Net
Page 1 of 1
5 Replies - 2108 Views - Last Post: 24 April 2012 - 12:02 PM
Replies To: Unchecking Checkboxes
#2
Re: Unchecking Checkboxes
Posted 20 November 2009 - 02:22 PM
What are the names you gave the groupbox, textboxes, and checkboxes.
This post has been edited by itistimmah: 20 November 2009 - 02:31 PM
#3
Re: Unchecking Checkboxes
Posted 20 November 2009 - 02:39 PM
if the checkboxes are in a groupbox which is in the container you call "C" then yes that is why its not working. You need to put groupbox in your select case statement and then loop through all the controls in the groupbox and look for the checkboxes inside it.
#4
Re: Unchecking Checkboxes
Posted 20 November 2009 - 03:04 PM
Your textboxes and checkboxes must both in the "C" groupbox for this to work. But it does work.
#5
Re: Unchecking Checkboxes
Posted 24 April 2012 - 11:40 AM
Use this formula for your piece of code
me.close
then (the form name with the button that opens me).(name of that button).performclick
Took me ages so i hope someone with same problem will find this
me.close
then (the form name with the button that opens me).(name of that button).performclick
Took me ages so i hope someone with same problem will find this
#6
Re: Unchecking Checkboxes
Posted 24 April 2012 - 12:02 PM
Assuming that C is your groupbox name then you could use
So for every control inside the groupbox named C
if the current control is a Checkbox then
Cast ctrl which is just an object at this point to a checkbox because we confirmed its type was a checkbox and set its .Checked Property = False
For each ctrl as Control in C.Controls
If TypeOf ctrl is Checkbox Then
CType(ctrl, Checkbox).Checked = False
End If
Next
So for every control inside the groupbox named C
if the current control is a Checkbox then
Cast ctrl which is just an object at this point to a checkbox because we confirmed its type was a checkbox and set its .Checked Property = False
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote





|