网格控制和值

时间:2016-03-22 12:36:04

标签: c# devexpress gridcontrol

我在click事件上使用一个按钮将产品添加到GridControl。在事件中,有一个计算项目的for循环。我的问题是,当点击事件时,它会将产品添加到网格中,但它不会计算项目。

我使用void方法计算并使用gridrowcount更改事件来调用它,但是,我不想这样做。我希望它在添加产品时计算。

void Hesapla()
{
    decimal Toplam = 0;

    for (int i = 0; i < gridView1.RowCount + 1; i++)
    {
        Toplam += decimal.Parse(gridView1.GetRowCellValue(i, "Tpl").ToString());

    }
    txtToplam.Text = Toplam.ToString("0.00");
    btnAdetText.Text = gridView1.RowCount.ToString() + " Ürün";
}

当我将RowCount更改为-1或+1时,会出错。

我添加产品的代码:

SimpleButton urun = (SimpleButton)sender;
UrunID = Convert.ToInt16(urun.Tag);
DataRow Dr = cls.urunSec(UrunID);
Ses2();
gridView1.AddNewRow();

gridView1.SetRowCellValue(DevExpress.XtraGrid.GridControl.NewItemRowHandle, "ID", Dr["ID"].ToString());
gridView1.SetRowCellValue(DevExpress.XtraGrid.GridControl.NewItemRowHandle, "STOKADI", Dr["STOKADI"].ToString());
gridView1.SetRowCellValue(DevExpress.XtraGrid.GridControl.NewItemRowHandle, "ADET", Adet);
gridView1.SetRowCellValue(DevExpress.XtraGrid.GridControl.NewItemRowHandle, "TOPLAM", Dr["SATISFIYAT"].ToString());

1 个答案:

答案 0 :(得分:0)

&#13;
&#13;
 private void urn_Click(object sender, EventArgs e)
        {
            // Hi 
            // ım add new product from here
            SimpleButton urun = (SimpleButton)sender;
            UrunID = Convert.ToInt16(urun.Tag);
            DataRow Dr = cls.urunSec(UrunID);
            Ses2();
            gridView1.AddNewRow();
            gridView1.SetRowCellValue(DevExpress.XtraGrid.GridControl.NewItemRowHandle, "ID", Dr["ID"].ToString());
            gridView1.SetRowCellValue(DevExpress.XtraGrid.GridControl.NewItemRowHandle, "STOKADI", Dr["STOKADI"].ToString());
            gridView1.SetRowCellValue(DevExpress.XtraGrid.GridControl.NewItemRowHandle, "MIKTAR", Adet);
            gridView1.SetRowCellValue(DevExpress.XtraGrid.GridControl.NewItemRowHandle, "BIRIMFIYAT", Dr["SATISFIYAT"].ToString());
            Hesapla();
        } 
I have added , but did not
&#13;
&#13;
&#13;