Wrox Programmer Forums
|
Pro VB.NET 2002/2003 For advanced Visual Basic coders working .NET version 2002/2003. Beginning-level questions will be redirected to other forums, including Beginning VB.NET.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB.NET 2002/2003 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 January 12th, 2005, 07:31 AM
Authorized User
 
Join Date: Dec 2004
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default Question for .NET GURUs

(I asked the following question on other forums but got n000 answer)

How do I retrieve the .Checked property of a checkbox in a form by cycling thru its controls collection, such as in

Dim AnyCtrl as Control

For AnyCtrl In MyForm.Controls
    if TypeOf AnyCtrl Is CheckBox then

       ?? ...get the "checked" status of the control... ???

    Next AnyCtrl

In VB6 there used to be the Controls("CheckBox") filter, which has been dumped in VB.Net :(, so how do you do the above in .NET ??

TIA




 
Old January 12th, 2005, 10:43 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 142
Thanks: 0
Thanked 2 Times in 2 Posts
Default

The following will work:

Code:
        Dim ctrl As Control, cb As CheckBox
        For Each ctrl In Me.Controls
            If ctrl.GetType.Name.ToLower = "checkbox" Then
                cb = CType(ctrl, CheckBox)
                Dim mssg As String
                If cb.Checked Then mssg = " is checked" Else mssg = " isn't checked"
                MessageBox.Show(cb.Name & mssg)
            End If
        Next
I appreciate it isn't quite as elegant as it could be (would be nice if you could do For Each CheckBox in Me.Controls), but it does the job.






Similar Threads
Thread Thread Starter Forum Replies Last Post
XML question for you XML Gurus SQLScott SQL Server 2005 1 June 25th, 2008 11:29 AM
Needs help from Gurus-regarding Windows Services avats VS.NET 2002/2003 1 August 9th, 2005 08:01 AM
Needing attention of .NET GURUS-Windows Service avats General .NET 4 August 8th, 2005 02:12 PM
Need help from Regex Gurus!!! sanch3x Classic ASP Basics 0 June 24th, 2005 12:05 PM
All u Gurus Out there Plz help ! augustine Biztalk 1 August 4th, 2004 08:57 AM





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