Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Visual Basic 2005 Basics
Password Reminder
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Display Modes
  #1 (permalink)  
Old September 25th, 2010, 10:55 PM
Authorized User
Join Date: Dec 2006
Location: Tucson, AZ, USA.
Posts: 43
Thanks: 4
Thanked 0 Times in 0 Posts
Send a message via MSN to Yasho
Red face Uncheck chkboxes

i have a groupbox with 18 checkboxes. I want to unchcek all checked boxes with Reset button click. can some on help me
i am using visual studio 2005. Thanks in advance

Here is more information

Dim ctrl As Control
Dim chkb As CheckBox
ForEach ctrl InMe.Controls
If (ctrl.GetType() IsGetType(CheckBox)) Then
chkb = CType(ctrl, CheckBox)
chkb.Checked = False
-----Comment---- The purpoe of Line above is to see whichcontrols this code is finding on the form.

This code works when I put all checkboxes on the form but when i put the checkboxes inside a groupbox then it doesnt do nothing. The messagebox.show(ctrl.tostring) tells me it does find the groupbox but doesnt see inside of the groupbox. When helping with the code please do explain me this behavior also.
Thanks a bunch in advance and i mean it

Last edited by Yasho; September 26th, 2010 at 12:33 AM. Reason: adding more information
Reply With Quote
  #2 (permalink)  
Old September 26th, 2010, 12:14 PM
Friend of Wrox
Points: 1,075, Level: 12
Points: 1,075, Level: 12 Points: 1,075, Level: 12 Points: 1,075, Level: 12
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2005
Location: , , United Kingdom.
Posts: 244
Thanks: 3
Thanked 4 Times in 4 Posts

If you read your code, your not handling any groupbox's all your checking for are checkboxes, and to see inside something else control array you need to specify that control array.

Its a simple fix, I would seperate out all the code.

 Private Sub Searcher(ByVal cntrl As Control)
        Dim n As ControlCollection = cntrl.Controls

        For Each ctrl As Control In n
            If ctrl.GetType = GetType(CheckBox) Then 'see if the ctrl is a checkbox
'The thing about this bit here, is if you tag all the chkboxes with a letter then
'you can check all these tags to make proper sure its the ones you want
'to disable. or you can find some other method, if you set this sub routine
'to start on the Form (i.e. Me) then it will recursively search all the controls on the form until it all done
                Dim chk As CheckBox = CType(ctrl, CheckBox) 'convert the ctrl to checkbox
                If Not chk.CheckState = CheckState.Unchecked Then 'this works for even three state checkboxes
                    chk.Checked = False
                End If
                    Searcher(ctrl) 'if the ctrl has a control array then search if it throws back an error skip over it
                Catch ex As Exception
                    Exit Sub
                End Try
            End If
    End Sub
You can take this a skeleton code and customise it to the ends of the earth to get it to check and so on forth and you can have do what ever in terms of searching, its pretty versatile!
Apocolypse2005, I'm a programmer - of sorts.
Reply With Quote
The Following User Says Thank You to Apocolypse2005 For This Useful Post:
Yasho (September 27th, 2010)

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Uncheck in groupbox of radio buttons alkh C# 0 November 8th, 2008 01:11 PM
radio button check/uncheck lisabb ASP.NET 2.0 Basics 2 May 24th, 2007 02:07 PM
check n uncheck items in checkboxlist in datalist moorejkrkumar ASP.NET 1.0 and 1.1 Basics 1 April 17th, 2007 01:39 PM
Dlookup with If ..Then ..Else and Chkboxes ecampos Access VBA 1 August 19th, 2005 01:51 PM
Dlookup with If ..Then ..Else and Chkboxes ecampos Access 16 August 18th, 2005 08:08 AM

All times are GMT -4. The time now is 02:12 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.