如何让DataGridViewCheckBoxColumn列只能选一行

billlyh 2010-04-23 10:49:14

第一列是个DataGridViewCheckBoxColumn,
是通过datagridview/属性/杂项/Columns/Collection 添加的

想在任一行沟中后,则其它行不能沟,

如何实现,?????????
...全文
381 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
捷哥1999 2010-04-23
  • 打赏
  • 举报
回复

'Check box column index
Private CheckColIndex As Integer = 0
Private Sub DataGridView1_CellValueChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged
'Check the column index and if the check box is checked.
If e.ColumnIndex = CheckColIndex Then
Dim isChecked As Boolean = CType(Me.DataGridView1(e.ColumnIndex, e.RowIndex).Value, Boolean)
If isChecked Then
'If check box is checked, uncheck all the rows, the current row would be checked later.
For Each row As DataGridViewRow In Me.DataGridView1.Rows
row.Cells(e.ColumnIndex).Value = False
Next
End If
End If
End Sub



billlyh 2010-04-23
  • 打赏
  • 举报
回复
7楼,你的思路和我的一样,
但是不知道用代码怎么实现
捷哥1999 2010-04-23
  • 打赏
  • 举报
回复
你在CheckBox中处理一下事件,在点击时,判断是否已经有其他的选中了,如果有,就把其他的设置为取消选中状态,保证当前的被选中。
xiaoyucaozhang 2010-04-23
  • 打赏
  • 举报
回复
你弄这个干什么?直接在DateGridView里面显示一行不久行了,
billlyh 2010-04-23
  • 打赏
  • 举报
回复
datagridview属性添加的列没有RadioBox列,
billlyh 2010-04-23
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 zhoufoxcn 的回复:]
CheckBox本来就是允许多选的,RadioBox才是单选的。
你可以在更改到数据库之前检查一下。
[/Quote]

datagridview属性添加的列没有RadioBox列,
Purple_Sky2010 2010-04-23
  • 打赏
  • 举报
回复
前台写个JS,判断下Checkbox选中的个数,如果大于1则提示、
周公 2010-04-23
  • 打赏
  • 举报
回复
CheckBox本来就是允许多选的,RadioBox才是单选的。
你可以在更改到数据库之前检查一下。
guyixin 2010-04-23
  • 打赏
  • 举报
回复
接分来了
cobra009 2010-04-23
  • 打赏
  • 举报
回复
用checkbox实现radiobutton的功能,强!

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧