简体   繁体   English

有时未选中DataGridView列中的复选框?

[英]Checkbox in a DataGridView column is not getting checked sometimes?

I use this code to check all the check-boxes in a data grid view in VB.NET ( 2010 - .NET Framework 4.0 ), 我使用此代码检查所有的复选框在VB.NET数据网格视图( 2010 - .NET框架4.0

Dim i As Integer
For i = 0 To (DataGridView.Rows.Count - 1)
    DataGridView.Rows(i).Cells(0).Value = True
Next

Sometimes when one of the row is selected (not checked but just the entire row is selected) while this code is running, it checks all other check-boxes in the column except the selected one. 有时,在运行此代码的同时选择了某一行(未选中但仅选中了整个行)时,它会选中该列中除选中的那一项以外的所有其他复选框。 What is wrong here? 怎么了

I also try adding this code, 我也尝试添加此代码,

DataGridView.SelectedCells(0).Cells(0).Value = True

Did not work. 不工作。

Like I said in the comments, the issue is that the box is checked in the datasource, but the GUI hasn't refreshed that cell to reflect it. 就像我在评论中所说的那样,问题在于该复选框在数据源中处于选中状态,但GUI尚未刷新该单元格以反映该信息。 If you click off of it, the cell should change/refresh to your new value. 如果单击它,则单元格应更改/刷新为新值。 After you have made your data changes, at the very end you should deselect cells/rows. 进行数据更改后,最后应取消选择单元格/行。 You can do it by: 您可以通过以下方式实现:

 Datagridview.ClearSelection() 

or 要么

 Datagridview.CurrentCell = Nothing 'deselects

You get the idea. 你明白了。 This is what has worked for me in the past. 这就是过去为我工作的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM