Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
计算“的总和”;“金额”;数据网格中的列';在WPF中打开DataGridTemplateColumn_Wpf_Wpf Controls_Wpfdatagrid_Wpftoolkit - Fatal编程技术网

计算“的总和”;“金额”;数据网格中的列';在WPF中打开DataGridTemplateColumn

计算“的总和”;“金额”;数据网格中的列';在WPF中打开DataGridTemplateColumn,wpf,wpf-controls,wpfdatagrid,wpftoolkit,Wpf,Wpf Controls,Wpfdatagrid,Wpftoolkit,我们有WPF应用程序,其中我们在一个表单上使用DataGrid。 现在我们要计算Winddow_加载事件上datagrid“AMOUNT”列的总数,这样它就可以在一个文本框中显示AMOUNT列的总数 当表单加载时。所以,如何遍历DATAGRID中的所有行并计算“AMOUNT”列的总数 如何在WPF Datagrid的页脚中显示此总数?Datagrid到DataTable。之后,您可以遍历所有行: double sum = 0; foreach (var row i

我们有WPF应用程序,其中我们在一个表单上使用DataGrid。 现在我们要计算Winddow_加载事件上datagrid“AMOUNT”列的总数,这样它就可以在一个文本框中显示AMOUNT列的总数 当表单加载时。所以,如何遍历DATAGRID中的所有行并计算“AMOUNT”列的总数

如何在WPF Datagrid的页脚中显示此总数?

Datagrid
DataTable
。之后,您可以遍历所有行:

        double sum = 0;
        foreach (var row in myTable)
        {
            sum += double.Parse(row["AMOUNT"].ToString());
        }
        myTextBox.Text = sum.ToString()

用于将DataGrid转换为数据集的函数:

namespace WpfApplication1
{
    static class ExtClass
    {
     public static DataSet ToDataSet<T>(this IList<T> list)
     {
         Type elementType = typeof(T);
         DataSet ds = new DataSet();
         DataTable t = new DataTable();
         ds.Tables.Add(t);

         //add a column to table for each public property on T
         foreach (var propInfo in elementType.GetProperties())
         {
             Type ColType = Nullable.GetUnderlyingType(propInfo.PropertyType) ?? propInfo.PropertyType;

             t.Columns.Add(propInfo.Name, ColType);
         }

         //go through each property on T and add each value to the table
         foreach (T item in list)
         {
             DataRow row = t.NewRow();

             foreach (var propInfo in elementType.GetProperties())
             {
                 row[propInfo.Name] = propInfo.GetValue(item, null) ?? DBNull.Value;
             }

             t.Rows.Add(row);
         }

         return ds;
     }

    }
}
命名空间WpfApplication1
{
静态类ExtClass
{
公共静态数据集ToDataSet(此IList列表)
{
类型元素类型=类型(T);
数据集ds=新数据集();
DataTable t=新的DataTable();
ds.表格.加入(t);;
//为T上的每个公共属性向表中添加一列
foreach(elementType.GetProperties()中的var propInfo)
{
Type ColType=Nullable.GetUnderlineType(propInfo.PropertyType)??propInfo.PropertyType;
t、 Columns.Add(propInfo.Name,ColType);
}
//检查T上的每个属性,并将每个值添加到表中
foreach(列表中的T项)
{
DataRow row=t.NewRow();
foreach(elementType.GetProperties()中的var propInfo)
{
行[propInfo.Name]=propInfo.GetValue(项,空)??DBNull.Value;
}
t、 行。添加(行);
}
返回ds;
}
}
}

编辑:格式化间距,使所有代码显示在代码块中

如何填充
数据网格
?我已通过在其中手动添加行填充了数据网格,当我们在编辑模式下打开表单时,届时将从数据库中提取数据。现在,当我们在编辑模式下打开表单时,从数据库填充DATAGRID,如何遍历它?好的,我会尝试&让您知道。谢谢你能帮我把DATAGRID转换成DATATABLE吗?我已经把DATAGRID转换成DATATABLE了。@ConstantLearner没问题:)