datagridview帮助中的复选框 [英] Check box in datagridview help
本文介绍了datagridview帮助中的复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经更新了我的代码但是,当取消选中该复选框时,它不会清除整行
私有 Sub dgvRecords_CellContentClick( ByVal sender As System。 Object , ByVal e As System.Windows.Forms.DataGridViewCellEventArgs)句柄 DataGridView1.CellContentClick
如果 e.ColumnIndex = 1 那么
Dim IsChecked As Boolean = 错误
IsChecked = CBool ( DirectCast (DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells( No Records ),DataGridViewCheckBoxCell)。EditedFormattedValue)
如果 IsChecked 那么
如果 MessageBoxButtons.YesNo 那么
如果 MsgBox( 此人是否参加?,MsgBoxStyle.YesNo, 出勤)= MsgBoxResult.Yes 然后
DataGridView1 .Rows(DataGridView1.CurrentRow.Index).Cells( Att。 (是/否))。值= Y
< span class =code-keyword> Else
DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells( Att。(Y / N))。值= N
结束 如果
其他
DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells.Clear()
结束 < span class =code-keyword>如果
结束 如果
结束 如果
解决方案
MessageBoxButtons.YesNo
为False时它会清除它们......这没有任何意义。你到底想要检查什么? MessageBoxButtons.YesNo
是一个枚举。它总是会返回相同的值。我想你只想把if声明拿出来,当 IsChecked
为假时,让Else部分执行。
I've updated my code however, it will not clear the entire row when the checkbox is unchecked
Private Sub dgvRecords_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
If e.ColumnIndex = 1 Then
Dim IsChecked As Boolean = False
IsChecked = CBool(DirectCast(DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells("No Records"), DataGridViewCheckBoxCell).EditedFormattedValue)
If IsChecked Then
If MessageBoxButtons.YesNo Then
If MsgBox("Did this person attend?", MsgBoxStyle.YesNo, "Attendance") = MsgBoxResult.Yes Then
DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells("Att. (Y/N)").Value = "Y"
Else
DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells("Att. (Y/N)").Value = "N"
End If
Else
DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells.Clear()
End If
End If
End If
解决方案
Your code doesn't clear the cells when it's unchecked...it's clearing them whenMessageBoxButtons.YesNo
is False...which makes no sense. What were you trying to check for at that point?MessageBoxButtons.YesNo
is an enumeration. It's always going to return the same value. I think you just want to take that If statement out, and leave the Else part to execute when theIsChecked
is false.
这篇关于datagridview帮助中的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文