![](/img/trans.png)
[英]Move the focus from a TextBox to another one when pressing the enter key of the soft keyboard
[英]can't automatically update the total value of the textbox when pressing the delete key on the keyboard
我想总结在第4列中自动输入的所有值并将其显示在文本框中。 我用这个代码:
private void totalAll()
{
int a = 0, b = 0;
for (a = 0; a < dataGridView1.Rows.Count; ++a)
{
b += Convert.ToInt32(dataGridView1.Rows[a].Cells[3].Value);
}
textBox1.Text = b.ToString();
}
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
foreach (DataGridViewRow row in dataGridView1.Rows)
totalAll();
}
一切正常,但是当我按下键盘上的删除键时,文本框的总值不会自动更新。 它的价值不会减少。
从数据网格视图中删除行时,应重新计算总值。
用户删除行时应该监听事件你应该在InitializedComponent();
之后添加它InitializedComponent();
在您的表单构造函数中。
dataGridView1.UserDeletedRow += (s, e) => totalAll();
尝试订阅dataGridView事件RowsRemoved。 我没有测试这个,但应该是这样的:
dataGridView1.RowsRemoved += (s,e) => totalAll();
顺便说一句,我认为你可以删除dataGridView1_CellEndEdit方法上的foreach,似乎什么都不做
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.