datagridview帮助中的复选框

编程入门 行业动态 更新时间:2024-10-27 03:33:58
本文介绍了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 Else DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells( Att。(Y / N))。值= N 结束 如果 其他 DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells.Clear() 结束 如果 结束 如果 结束 如果

解决方案 你的代码在取消选中时不会清除单元格......当 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 when MessageBoxButtons.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 the IsChecked is false.

更多推荐

datagridview帮助中的复选框

本文发布于:2023-11-07 09:03:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1566051.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:复选框   datagridview

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!