询问者
datagridview单元格正在编辑,焦点的问题

问题
全部回复
-
Hi,
欢迎在MSDN论坛发帖。
你可以上传一份可以重现问题的demo到one drive 上面吗? 这样方便我测试问题,我这边没有办法重现你的问题, 你是怎么调用textchange 事件?
Best Regards,
Hart
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
-
https://1drv.ms/f/s!AqRPeMytWdHmgQ5IkKA4CUQ64qMd
这个是项目的源代码,麻烦帮我看看,谢谢!
先修改商品单价或者数量,然后切换到总价,修改总价就会重现该问题了- 已编辑 LeadingServer 2018年1月17日 2:24
-
Hi,
我测试你的代码,并没有发现焦点错乱的样子。
Best Regards,
Hart
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
-
Hi,
我测试你问题,根据你的描述,总价那个地方不能输入两位以上的数字。
焦点总是选中数字,而且是1位。
我分析和测试,可能是下面这个代码写的有问题。
double amount = (sender as TextBox).Text == "" ? 0 : Convert.ToDouble((sender as TextBox).Text); orderdgv.CurrentRow.Cells["Amount"].Value = amount; int num = Convert.ToInt32(orderdgv.CurrentRow.Cells["Num"].Value); orderdgv.CurrentRow.Cells["Price"].Value = amount / num; orderdgv.CurrentCell.Selected = false;
当你按下一个键值,这个Tb_TextChanged 事件总是会被触发,然后你就获取当前text的值,此时的值肯定是一位数字,不会出现45双位数字,但当你再次按下5时,又一次处罚Tb_TextChanged 事件,此时text的值肯定是5,不会保留上次输入的4.
我尝试用static 变量的家记忆性,保留上次的值,单步调试,没有问题,运行就会超出double的精度。
Best Regards,
Hart
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
-
Hi,
static变量加载这个地方,来保存上次text上面的值,使用这个方案的原因,是因为每次输入一个数字键值,都会触发textchanged事件,我想保存上次的text值,然后进行追加的方式,得到真正的值,但是这个方案在我这边测试失败。
static string receive_value; private void Tb_TextChanged(object sender, EventArgs e) { double amount = (sender as TextBox).Text == "" ? 0 : Convert.ToDouble((sender as TextBox).Text); receive_value += amount.ToString();
}
Best Regards,
Hart
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.