Solved

How to check state of Checkbox in a tablelayoutpanel

Posted on 2009-05-04
8
553 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
 
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now