|
-
Aug 11th, 2008, 03:35 PM
#1
Thread Starter
Hyperactive Member
Check all boxes in a datagridview (Resolved)
I am trying to check all the text boxes in a datagrid view with this
VB Code:
Dim ctl As Control
Dim cbx As CheckBox
For Each ctl In Me.dgvPosiPay.Controls
If ctl.GetType Is cbx.GetType Then
ctl = DirectCast(ctl, CheckBox)
If ctl.Checked = False Then
ctl.checked = True
End If
End If
Next
I am getting the error 'checked' is not a member of 'System.Windows.Forms.Control'. and it is underlining the ctl.checked in the second if statement. I am pretty sure my problem is with the Me.dgvPosiPay.Controls part of the code block but I am not sure what the correct syntax should be.
Last edited by FastEddie; Aug 12th, 2008 at 09:37 AM.
-
Aug 11th, 2008, 07:35 PM
#2
Re: Check all boxes in a datagridview
VB Code:
For Each ctl As Windows.Forms.Control In Me.dgvPosiPay.Controls
If TypeOf ctl Is CheckBox Then _
DirectCast(ctl, CheckBox).Checked = True
Next
Although, I'm pretty sure that this won't catch them. You're going to have to iterate through your datagridviewcells to find them.
-
Aug 12th, 2008, 09:36 AM
#3
Thread Starter
Hyperactive Member
Re: Check all boxes in a datagridview
This may not be the most elegant way to accomplish my goal but it worked so I am posting it so that others may use it.
VB Code:
Private Sub CheckAll()
Dim j As Integer
Try
For j = 0 To ds.Tables(0).Rows.Count - 1
dgvPosiPay.Item(6, j).Value = CheckState.Checked
Next
Catch ex As Exception
Throw New Exception(ex.Message)
End Try
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|