Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 698
  • Last Modified:

How to check state of Checkbox in a tablelayoutpanel

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
GarySB
Asked:
GarySB
  • 3
  • 3
  • 2
2 Solutions
 
hnasrCommented:
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
 
GarySBAuthor Commented:
I just tried it and it says: Checked is not a member of 'System Windows.Forms.Control'
0
 
hnasrCommented:
Try
     If NewTab_TableLayoutPanel.GetControlFromPosition(RowPosition + 0, ColumnPosition + 1).CheckState = 1 Then
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
game-masterCommented:


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
 
game-masterCommented:


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
 
GarySBAuthor Commented:
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
 
GarySBAuthor Commented:
Thank You.  I was able to apply the dim technique to my datepicker as well.
0
 
game-masterCommented:

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now