不定期更新datagridview单元格值 [英] Not updating the datagridview cell values regularly

查看:80
本文介绍了不定期更新datagridview单元格值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

当我在datagridview中更新单元格值时,它不会定期更新.
我的datagrid中控件的复选框是checkbox.当我选中或取消选中该复选框以及当我

调试事件CellClick,获取正确的单元格值(错误或正确

敬请谅解.)
后立即
没有单击任何其他复选框,而当我单击同一复选框时却没有得到

正确的值,但获得与以前相同的值(即错误或正确地尊重),与

之前.但是复选框显示为未选中或已选中).但是在
之后
单击其他任何一个复选框,如果我再次单击该复选框,它将得到

正确的值.请帮助我.我在此问题上遇到问题

在此先感谢.

Hello all,

When I am updating cell value in a datagridview it is not updating regularly.One

of the control in my datagrid is checkbox.When I check or uncheck the checkbox and when I

debug the event CellClick it is getting correct cell value(That is false or true

respectievely).Immediate after

without clicking any other checkbox when I click that same checbox it is not getting the

correct value but getting the same value as before(That is false or true respectievely)as

before.But the checkbox is showing unchecked or checked respectievely).But after

clicking any of the other check box and if I am clicking that checkbox again it is getting

the correct value.Please help me.I am having a trouble with this issue

Thanks in advance .

推荐答案

单击DataGridView的复选框时,它将处于脏状态,而单击另一个单元格或行时,数据将坚定的.在您的情况下,当您单击复选框并且不单击其他位置时,CurrentCell将处于脏状态.如下所示处理以下事件以提交数据

When a check box of DataGridView is clicked, it will be in dirty state and when another cell or row is clicked the data will be committed. In your case when you click the check box and do not click elsewhere then the CurrentCell will be in dirty state. Handle the following event as shown below to commit the data

void dataGridView1_CurrentCellDirtyStateChanged(object sender,
EventArgs e)
{
    //replace ColumnIndex == 1 in the following code with column index of your check box column
    if (dataGridView1.CurrentCell.ColumnIndex== 1 && dataGridView1.IsCurrentCellDirty)
    {
    	dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
    }
}



如果您的问题已解决,则可以接受并投票解决方案,否则可以发布您的查询.



You may accept and vote solution if your problem is solved, otherwise post your queries.


您好,朋友...


正如您所说的,您看不到datagridview.right的更新值.

所以您可以尝试一下,希望它能解决您的问题...


在复选框的末尾或任何会影响gridview单元格值的事件中,您需要在逻辑代码的末尾再添加一行,就像这样...
Hello freind...


As you say you cant see the updated value to your datagridview.right...

so you can try this i hope it will solve your problem...


at the end of checkbox or any event which will affect your gridview cell value you need to put one more line at the end of your logical code like this...
DataGridView1.Refresh();



我希望它对您有用....



i hope it will work for you....


使用datagridview1.AcceptChanges()


这很好.测试了.


使用并提供您的反馈意见:D
use datagridview1.AcceptChanges()


this is working fine. tested it.


use and give ur feedback :D


这篇关于不定期更新datagridview单元格值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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