Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 25th, 2010, 10:55 PM
Authorized User
 
Join Date: Dec 2006
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
EndIf
'MessageBox.Show(ctrl.ToString)
-----Comment---- The purpoe of Line above is to see whichcontrols this code is finding on the form.
Next

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
__________________
yvk

Last edited by Yasho; September 26th, 2010 at 12:33 AM.. Reason: adding more information
 
Old September 26th, 2010, 12:14 PM
Friend of Wrox
 
Join Date: Jun 2005
Posts: 244
Thanks: 3
Thanked 4 Times in 4 Posts
Default

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.

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
            Else
                Try
                    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
        Next
    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.
The Following User Says Thank You to Apocolypse2005 For This Useful Post:
Yasho (September 27th, 2010)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Uncheck in groupbox of radio buttons alkh C# 0 November 8th, 2008 02: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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.