Solved

How to check state of Checkbox in a tablelayoutpanel

Posted on 2009-05-04
8
650 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses
Course of the Month9 days, 1 hour left to enroll

615 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