Unchecking Checkboxes

Unchecking Checkboxes in VB.Net

Page 1 of 1

5 Replies - 2108 Views - Last Post: 24 April 2012 - 12:02 PM Rate Topic: -----

#1 NH20  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 20-November 09

Unchecking Checkboxes

Posted 20 November 2009 - 02:01 PM

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

Is This A Good Question/Topic? 0
  • +

Replies To: Unchecking Checkboxes

#2 itistimmah  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 19-November 09

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

Was This Post Helpful? 0
  • +
  • -

#3 bflosabre91  Icon User is offline

  • go sabres

Reputation: 105
  • View blog
  • Posts: 1,433
  • Joined: 22-February 08

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.
Was This Post Helpful? 0
  • +
  • -

#4 itistimmah  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 19-November 09

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.
Was This Post Helpful? 0
  • +
  • -

#5 welly99  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 22-April 12

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
Was This Post Helpful? 0
  • +
  • -

#6 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1397
  • View blog
  • Posts: 4,494
  • Joined: 25-September 09

Re: Unchecking Checkboxes

Posted 24 April 2012 - 12:02 PM

Assuming that C is your groupbox name then you could use

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
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1