如何清除C#.Net中未绑定DataGridView中的单元格值 [英] how to clear a cell value in a unbound DataGridView in C#.Net
问题描述
亲爱的专家;
我有一个datagridview,并在其中添加了一些列.它们是单价,特别是单价,数量和总价值.根据单价和数量计算的总价值,即总价值=单价*数量.我可以在此datagridview中添加5个项目并计算总值的总值.但是我的问题是,当我尝试更改数量或单价时,然后在更改数量或
之前更改了总值
单价 .我在下面添加我的代码
Dear Expert;
I have a datagridview and i add some columns in it . they are slno, particular ,unit price ,qty and gross value. the gross value calculated on the basis of unit price and qty that is gross value= unit price* qty. i can add 5 items in this datagridview and calculate the gross total of gross value.But my problem is when i try to change the qty or unit price ,then the gross value changed before change the qty or
unit price . i add my code bellow
private void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e)
{
a = Convert.ToInt32(dataGridView1.CurrentRow.Cells[2].Value);
b = Convert.ToInt32(dataGridView1.CurrentRow.Cells[3].Value);
dataGridView1.CurrentRow.Cells[4].Value = a * b;
//ng = 0;
c = Convert.ToInt32(dataGridView1.CurrentRow.Cells[4].Value);
ng = ng + Convert.ToDouble(c);
textBox1.Text = "";
textBox1.Text = ng.ToString();
}
请帮助我
please help me
推荐答案
您必须对以下所示事件进行计算...
私有void grd_bill_master_CellValueChanged(对象发送者,DataGridViewCellEventArgs e)
{
//您的代码
}
you have to perform your calculations on the event shown below...
private void grd_bill_master_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
// your code
}
并清除未绑定的单元格值
grd.Rows [int no] .Cell [int no] .Value =您的值";
and to clear unbound cell value
grd.Rows[int no].Cell[int no].Value="your value";
这篇关于如何清除C#.Net中未绑定DataGridView中的单元格值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!