读书人

小弟我想在DATAGRIDVIEW中(CGVIEW)录入

发布时间: 2012-04-15 18:39:21 作者: rapoo

我想在DATAGRIDVIEW中(CGVIEW)录入数量,单价后,金额自动生成,为什么这段代码没反映

C# code
        private void UpdateBalance()        {            int i;            int account;            int qty;            int price;            for (i = 1; i < (CGVIEW.Rows.Count - 1);i++)            {                qty = 0;                price = 0;                account = int.Parse(CGVIEW.Rows[i - 1].Cells["ACCOUNT"].Value.ToString());                if (CGVIEW.Rows[i].Cells["QTY"].Value != null)                {                    if (CGVIEW.Rows[i].Cells["QTY"].Value.ToString().Length != 0)                    {                        qty = int.Parse(CGVIEW.Rows[i].Cells["QTY"].Value.ToString());                    }                }                if (CGVIEW.Rows[i].Cells["PRICE"].Value != null)                {                    if (CGVIEW.Rows[i].Cells["PRICE"].Value.ToString().Length != 0)                    {                        price = int.Parse(CGVIEW.Rows[i].Cells["PRICE"].Value.ToString());                    }                }                CGVIEW.Rows[i].Cells["ACCOUNT"].Value =(qty*price).ToString();            }        }        private void CGVIEW_CellValueChanged(object sender, DataGridViewCellEventArgs e)        {            UpdateBalance();        }


[解决办法]
我上面的代码可以通过数量*单价计算金额,也可以通过数量和金额来计算单价。只是VB.net写的。不明白再说吧。

读书人网 >C#

热点推荐