C# 计算特定列';我的数据网格中的总值
我试图在我的C# 计算特定列';我的数据网格中的总值,c#,wpf,datagrid,C#,Wpf,Datagrid,我试图在我的datagrid中获取SellingPrice列中的总值。我如何计算c#编码中的总数量 如果您需要关于我使用的代码/类的更多信息,请随时询问。我会尽快给你的:)谢谢 编辑我要在标签中显示总量在视图模型中,创建只读属性: public double SumOfSomething { get { return YourCollection.Sum(x => x.ItemSellingPrice); } } <label Cont
datagrid
中获取SellingPrice列中的总值。我如何计算c#编码中的总数量
如果您需要关于我使用的代码/类的更多信息,请随时询问。我会尽快给你的:)谢谢
编辑我要在标签中显示总量在视图模型中,创建只读属性:
public double SumOfSomething
{
get
{
return YourCollection.Sum(x => x.ItemSellingPrice);
}
}
<label Content="{Binding SumOfSomething}"/>
然后可以将标签绑定到此属性:
public double SumOfSomething
{
get
{
return YourCollection.Sum(x => x.ItemSellingPrice);
}
}
<label Content="{Binding SumOfSomething}"/>
在视图模型中,创建只读属性:
public double SumOfSomething
{
get
{
return YourCollection.Sum(x => x.ItemSellingPrice);
}
}
<label Content="{Binding SumOfSomething}"/>
然后可以将标签绑定到此属性:
public double SumOfSomething
{
get
{
return YourCollection.Sum(x => x.ItemSellingPrice);
}
}
<label Content="{Binding SumOfSomething}"/>
我假设您有一个项目列表,并将其绑定到您的
数据网格的项目资源。此外,我假设您有一个名为\u Label
的标签。那么你的c#看起来像:
public class Item
{
public int ItemId { get; set; }
public int ItemCode { get; set; }
public string ItemDescription { get; set; }
public double ItemSellingPrice { get; set; }
public int QTY { get; set; }
}
public class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
var items = new List<Item>();
_dataGrid.ItemsSource = items;
var totalAmount = items.Sum(i => i.ItemSellingPrice);
_label.Content= totalAmount;
}
}
公共类项目
{
公共int ItemId{get;set;}
公共int ItemCode{get;set;}
公共字符串ItemDescription{get;set;}
公共双项目SellingPrice{get;set;}
公共整数数量{get;set;}
}
公共类主窗口:窗口
{
公共主窗口()
{
初始化组件();
var items=新列表();
_dataGrid.ItemsSource=项目;
var totalAmount=items.Sum(i=>i.ItemSellingPrice);
_label.Content=totalAmount;
}
}
我假设您有一个项目列表,并将其绑定到您的数据网格的项目资源。此外,我假设您有一个名为\u Label
的标签。那么你的c#看起来像:
public class Item
{
public int ItemId { get; set; }
public int ItemCode { get; set; }
public string ItemDescription { get; set; }
public double ItemSellingPrice { get; set; }
public int QTY { get; set; }
}
public class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
var items = new List<Item>();
_dataGrid.ItemsSource = items;
var totalAmount = items.Sum(i => i.ItemSellingPrice);
_label.Content= totalAmount;
}
}
公共类项目
{
公共int ItemId{get;set;}
公共int ItemCode{get;set;}
公共字符串ItemDescription{get;set;}
公共双项目SellingPrice{get;set;}
公共整数数量{get;set;}
}
公共类主窗口:窗口
{
公共主窗口()
{
初始化组件();
var items=新列表();
_dataGrid.ItemsSource=项目;
var totalAmount=items.Sum(i=>i.ItemSellingPrice);
_label.Content=totalAmount;
}
}
获取总金额,但以何种方式获取?你想再有一个写着什么东西的专栏吗?谢谢你的回复!我想在标签中显示总金额。只需循环查看数据源和sum ItemSellingPrice您找到答案了吗?获取总金额,但以何种方式?你想再有一个写着什么东西的专栏吗?谢谢你的回复!我想在标签中显示总金额。只需循环查看数据源和总和ItemSellingPrice您找到答案了吗?无MVVM正确+对于无MVVM来说是正确的+