Infragistics过滤行扫描。目标是基于列的所有过滤行的总和

时间:2017-03-06 20:40:38

标签: infragistics windows-forms-designer

我有Infragistics UltraGrid,它在不同条件下过滤。现在我想从过滤行结果中总结几列。检查以下代码

UltraGridColumn column = this.ugResults.DisplayLayout.Bands[0].Columns["Air45HValue"];
double a = 0;
for (int i = 0; i < filtInCnt; i++)
{
    if (ugResults.Rows[i].GetCellValue(column) != DBNull.Value)
    {
        a = a + Convert.ToDouble(ugResults.Rows[i].GetCellValue(column));
    }
}

这不能给我一个正确的答案。我认为,计算是在原始数据源上进行,而不是在过滤数据源上进行。如何在过滤结果上执行上述功能?

1 个答案:

答案 0 :(得分:3)

我在一个小样本应用程序中测试时,您的代码看起来是正确的。但是,我没有看到您如何获得filtInCnt,因为我建议您使用ugResults.Rows.GetFilteredInNonGroupByRows()。此方法返回所有已过滤的行。然后你应该为每个集合并执行计算。这是代码:

namespace WindowsFormsApplication1
{
    using System;
    using System.Data;
    using System.Windows.Forms;
    using Infragistics.Win;
    using Infragistics.Win.UltraWinGrid;

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.ultraGrid1.DisplayLayout.Override.AllowRowFiltering = DefaultableBoolean.True;
            this.ultraGrid1.DisplayLayout.Override.FilterUIType = FilterUIType.FilterRow;

            this.ultraGrid1.DataSource = GetDataTable();
        }

        private DataTable GetDataTable(int rows = 100)
        {
            DataTable table = new DataTable("Table1");

            table.Columns.Add("Integer column", typeof(int));
            table.Columns.Add("DateTime column", typeof(DateTime));
            table.Columns.Add("String column", typeof(string));

            for (int i = 0; i < rows; i++)
            {
                DataRow row = table.NewRow();
                row["Integer column"] = i;
                row["String column"] = "text";
                row["DateTime column"] = DateTime.Today.AddDays(i);
                table.Rows.Add(row);
            }

            return table;
        }

        private void ultraButton1_Click(object sender, EventArgs e)
        {
            UltraGridColumn column = this.ultraGrid1.DisplayLayout.Bands[0].Columns["Integer column"];
            double a = 0;
        foreach(var row in    this.ultraGrid1.Rows.GetFilteredInNonGroupByRows())
        {
            var cellValue = row.GetCellValue(column);
            if(cellValue != DBNull.Value)
            {
                a = a + Convert.ToDouble(cellValue);
            }
        }

            MessageBox.Show("Result: " + a);
        }
    }
}