【问题标题】:Gridcontrol Sum Value网格控制总和值
【发布时间】:2016-03-22 23:45:05
【问题描述】:

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

我使用 void 方法来计算并使用 gridrowcount changed 事件调用它,但是,我不想要这个。我希望它在添加产品时进行计算。

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());

【问题讨论】:

  • 添加新行后为什么不直接调用Hesapla();?还要确保gridView1.GetRowCellValue(i, "Tpl") 实际上正在返回一些东西。我真的看不出Tpl 是否是提供的代码中的字段值。
  • Tpl 是未绑定的列名。并使用 ADET*TOPLAM 列。
  • 当添加 2 项时计算我想要添加一个产品时计算单词
  • 感谢您的回复
  • 您有任何异常吗?但有一件事,GetRowCellValue() 中的 rowHandle 参数是一个从零开始的索引,这意味着它从 0 开始。RowCount 表示网格中可见行的数量。假设有 5 行,您的行句柄只能从 0..4 开始,因为它从零开始。因此,在您的 for 循环中,您将从 0..RowCount 开始。您应该在 for 循环 for (int i = 0; i &lt; gridView1.RowCount; i++) 中使用它,因为小于号会将其限制为 0..RowCount - 1

标签: c# devexpress gridcontrol


【解决方案1】:

 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

【讨论】:

  • 我解决了谢谢。我使用gridview1.Refreshdata。最好的告白
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-10-19
  • 2012-06-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多