更新DataGridView当前行的复选框 [英] Updating check box of current row of DataGridView

查看:59
本文介绍了更新DataGridView当前行的复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
奇怪的问题.我有一个带CheckBox列的DataGridView.
我正在尝试以编程方式设置Checkbox列的值.
问题是所有行都更新了检查,但是由于某种原因,UI不会更新当前行(主要是选中的行,但仍然有例外).
在调试时,我发现我的代码可以正确执行所有操作.这是代码段-

Hey guys,
Weird issue. I am having a DataGridView with a CheckBox Column.
I am trying the set the values of the Checkbox column programmatically.
The issue is that all rows gets the check updated, but for some reason, the UI doesn''t update the current row (mostly the selected one, but it still has the exception).
On debugging, I found that my code does every thing correctly. Here is the snippet -

foreach (DataGridViewRow Row in dgvIgnoreApp.Rows)
{
    // CheckBoxColumn
    Row.Cells[0].Value = m_chkColumnHeaderIgnore.CheckAll; // Some Boolean value
}
dgvIgnoreApp.Invalidate();



我尝试搜索OL,而我最想去的地方是人们建议我使用DataGridView.CommitEdit()或DataGridView.EndEdit()的地方.新代码如下所示-



I tried searching OL and the most I could go is where people suggested me to use DataGridView.CommitEdit() or DataGridView.EndEdit(). The new code looks like this -

foreach (DataGridViewRow Row in dgvIgnoreApp.Rows)
{
    if (Row.Cells[0].Selected) // CheckBoxColumn
         dgvIgnoreApp.BeginEdit(false);

    Row.Cells[0].Value = m_chkColumnHeaderIgnore.CheckAll;

    if (Row.Cells[0].Selected)
         dgvIgnoreApp.EndEdit();
}
dgvIgnoreApp.Invalidate();



我使用了它,但是它仍然给我相同的结果.
是MS .Net错误吗?帮帮我...
在此先感谢.



I used that but it is still giving me the same result.
Is it a MS .Net Bug? Help me guys...
Thanks in advance.

推荐答案

我可以解决这个问题,但是不知道为什么会这样?

I got a work around but don''t know why this happened?

foreach (DataGridViewRow Row in dgvIgnoreApp.Rows)
{    
    // CheckBoxColumn
    Row.Cells[0].Value = m_chkColumnHeaderIgnore.CheckAll; // Some Boolean value
}
dgvIgnoreApp.Enabled = false; //Miracle Line
dgvIgnoreApp.Enabled = true;  //Miracle Line



出于原因和更好的答案,讨论仍在进行中.
谢谢大家.

-
Varun



Discussion is still on for reasons and better answers.
Thanks you all.

--
Varun


尝试一下:-

而不是编写以下代码:-
Try this:-

Instead of this write this code:-
Row.Cells[0].Value = m_chkColumnHeaderIgnore.CheckAll;



写这个:-



Write this:-

Row.Cells[0].Value = CheckState.Checked;



如有任何问题,请发表评论或回复.



Any problem please comment or reply.


这篇关于更新DataGridView当前行的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆