Solved

How to check state of Checkbox in a tablelayoutpanel

Posted on 2009-05-04
8
629 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
Technology Partners: 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

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…
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.
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…

751 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