datagridview中的行计数未更新 [英] Row count in datagridview is not updating

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

问题描述

我添加了一个gridview,其中添加了项目并调用了一个函数来计算金额



将项目添加到列表后我打电话



I have added a gridview in which items are added and a function is called to calculate the amount

after adding a item to list i call

Private Sub totalimsum()
    Dim totalsum As Double = 0
    Dim totalitem As Double = 0

    For i As Integer = 0 To dgvitemlist.Rows.Count - 1
        totalsum += dgvitemlist.Rows(i).Cells("Total").Value
        'totalitem += dgvitemlist.Rows(i).Cells("qty").Value
    Next
    Label16.Text = dgvitemlist.Rows.Count.ToString()
    amttotal = totalsum.ToString()
    txttotal.Text = amttotal
    calctotal()
End Sub





它完美无缺,但当一行被删除时,我再次调用该函数重新计算金额,但它错误地计算金额,我发现rowcount比datagridview中的行多1,所以我添加了一个新函数并调用它,但我认为它不是一个解决方案





it works perfect but when a row got deleted, I again call the function to recalculate the amount but it miscalculate the amount and I found that rowcount is 1 more than row present in the datagridview so i added a new function and calling it but i think it is not a solution

   Private Sub totalimsumd()
    Dim totalsum As Double = 0
    Dim totalitem As Double = 0

    For i As Integer = 0 To dgvitemlist.Rows.Count - 2
        totalsum += dgvitemlist.Rows(i).Cells("Total").Value
        'totalitem += dgvitemlist.Rows(i).Cells("qty").Value
    Next
    Label16.Text = dgvitemlist.Rows.Count.ToString()
    amttotal = totalsum.ToString()
    txttotal.Text = amttotal
    calctotal()
End Sub





请帮助获得解决方案。



Kindly help to get the solution.

推荐答案

你能给我一行删除功能吗?我认为你没有完全删除该行。

如果完全删除,则计数也应该减少。
can you please give me the row delete function ? i think you didn't completely delete the row.
if it is completely delete the count should decrease too.


使用行或单元格点击事件来帮助存储seletedrows

并使用selectedrows作为删除datagridview中数据的整行的索引,如下所示





use the row or cell click event to help store seletedrows
and use selectedrows to be the index to delete the entire row of the data in datagridview like this


private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
    DataGridView dgv = sender as DataGridView;
    if (dgv == null)
        return;
    if (dgv.CurrentRow.Selected)
    {
        int selectedrows = 0;
        selectedrows = dgv.CurrentRow.Index;
        dgv.removeat(selectedrows); 
        //do rest you staff.
    }
}



它应该起作用:)


it should work : )


这篇关于datagridview中的行计数未更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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