Solved

How to check state of Checkbox in a tablelayoutpanel

Posted on 2009-05-04
8
610 Views
Last Modified: 2012-05-06
Please tell me how I can modify the 2nd IF statement to determine if the checkbox is checked, Thank You
I'm using the following code to first determine if a column contains a checkbox.
                If TypeOf (NewTab_TableLayoutPanel.GetControlFromPosition(RowPosition,ColumnPosition)) Is CheckBox Then

Next I want to know if the checkbox is checked.  This is not working.
                    If NewTab_TableLayoutPanel.GetControlFromPosition(RowPosition + 0, ColumnPosition + 1).CheckState = True Then

0
Comment
Question by:GarySB
  • 3
  • 3
  • 2
8 Comments
 
LVL 30

Expert Comment

by:hnasr
ID: 24298877
Use Checked property

 If NewTab_TableLayoutPanel.GetControlFromPosition(RowPosition + 0, ColumnPosition + 1).Checked = True Then
Or simply
If (NewTab_TableLayoutPanel.GetControlFromPosition(RowPosition + 0, ColumnPosition + 1).Checked) Then
0
 

Author Comment

by:GarySB
ID: 24299058
I just tried it and it says: Checked is not a member of 'System Windows.Forms.Control'
0
 
LVL 30

Assisted Solution

by:hnasr
hnasr earned 50 total points
ID: 24300263
Try
     If NewTab_TableLayoutPanel.GetControlFromPosition(RowPosition + 0, ColumnPosition + 1).CheckState = 1 Then
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Expert Comment

by:game-master
ID: 24302878


good afternoon!

try sumthing like this...

Dim y As CheckBox
        For Each y In Me.TableLayoutPanel1.Controls
            If y.Checked = True Then
                y.Checked = False
                'do ur code here
            Else
                y.Checked = True
                y.Checked = True
            End If
        Next


i hope i could give u idea...

game-master
0
 
LVL 13

Accepted Solution

by:
game-master earned 125 total points
ID: 24302905


im sorry!

here's the code...


Dim y As CheckBox
        Dim x As Control
        For Each x In Me.TableLayoutPanel1.Controls
            If TypeOf x Is CheckBox Then
                y = x
                If y.Checked = True Then
                    y.Checked = False
                    'do ur code here
                Else
                    y.Checked = True
                    y.Checked = True
                End If
            End If
        Next
0
 

Author Comment

by:GarySB
ID: 24303986
This worked:
Dim y As CheckBox = NewTab_TableLayoutPanel.GetControlFromPosition(RowPosition + 0, ColumnPosition + 0)
If y.Checked = True Then ...

Before I assign the points I would like to ask game-master why is it that the source control itself restricts certain properties and assigning the same control to a type 'Dim y as CheckBox' brings them all back?

hnasr: both the checked & checkstate properties are not available referencing the source control.
0
 

Author Closing Comment

by:GarySB
ID: 31577737
Thank You.  I was able to apply the dim technique to my datepicker as well.
0
 
LVL 13

Expert Comment

by:game-master
ID: 24310450

good morning!
i'm glad i could help you...

the thing that i can see is that the properties of the source control are the common
properties of some controls... e.g checked property is not a property of a button.

assigning the source control to 'y' which is a checkbox control, gets all the properties
of that certain control...


did you get my explanation sumhow...:-)


game-master
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question