Hi,
I have a datagridview and in it a column of checkboxes. How can I get it to where IF ANY of the checkboxes in that column are clicked on (event change), then a MessageBox will show up...
Thanks for the help!!!
Printable View
Hi,
I have a datagridview and in it a column of checkboxes. How can I get it to where IF ANY of the checkboxes in that column are clicked on (event change), then a MessageBox will show up...
Thanks for the help!!!
I have something like:
This works, but it works for ALLL the columns. I only want it to do it for the column with the checkbox in it.Code:Private Sub dgvWeldingLog_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvWeldingLog.CellContentClick
MessageBox.Show("hello", "world", MessageBoxButtons.OK, MessageBoxIcon)
End Sub
If you look in your event signature you will see the variable 'e'. If you access the members of said variable you will see some properties that will help you.
Replace YourColName with the column name to work with. I do not check to see the type of column as I am sure the name is correct in regards to YourColName is a CheckBox column type.
Code:Private Sub DataGridView1_CellValueChanged( _
ByVal sender As Object, _
ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) _
Handles DataGridView1.CellValueChanged
If DataGridView1.CurrentRow IsNot Nothing Then
If e.ColumnIndex = DataGridView1.Columns("YourColName").Index Then
If CBool(DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells("YourColName").Value) Then
MsgBox("Checked")
Else
MsgBox("UnChecked")
End If
End If
End If
End Sub
As per ForumnAccount
Code:Private Sub DataGridView1_CellContentClick( _
ByVal sender As Object, _
ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) _
Handles DataGridView1.CellContentClick
If DataGridView1.CurrentRow IsNot Nothing Then
If e.ColumnIndex = DataGridView1.Columns("YourColName").Index Then
If CBool(DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells("YourColName").Value) Then
MsgBox("YourColName")
Else
MsgBox("UnChecked")
End If
End If
End If
End Sub
Also here is a demo I did with what I call dualling checkbox columns
http://www.vbforums.com/showpost.php...34&postcount=9
Thanks for the response! I finally figured it out before I even read your post. This seems to work...so far:
Code:Private Sub dgvstuff_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvstuff.CellContentClick
If dgvstuff.CurrentRow.Cells("dgvcheckboxcolumn").Selected = True Then
MessageBox.Show("hello", "world", MessageBoxButtons.OK, MessageBoxIcon.Hand)
End If
End Sub
Here is a working copy where only the first CheckBox column is done with a Msgbox. This attached VS2008 is a slimmed down version of the one I suggested you review in an earlier post.