怎么添加汇总行啊……求高手
解决方案 »
- 如何将一个Form中的dataGridView的所有数据绑定到另一个Form中的dataGridView
- Ascii <--> Hex
- StreamReader.ReadLine() 问题。
- VS2005 项目中设计版面添加按钮 运行没反应
- Winfrom下的datagridview的空白行中的某可编辑列输入一值然后(根据改值从数据库某表中检索相关数据插入到datagridview数据源中并显示)
- 将字符串转换为 uniqueidentifier 时失败。
- 请问一下DataGrid里面怎样自己设置列名
- 怎样用C#连接客户端(XP系统)
- DataGrid问题
- 问一个有关参数写法的问题?急盼回答!谢谢
- 求一个正则表达式
- 使用Netsh虚拟Wifi如何获取密码
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="" Height="400" Width="550" >
<DockPanel>
<StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" HorizontalAlignment="Right">
<TextBlock>Total:</TextBlock>
<TextBlock Margin="30, 0, 0, 0" Text="{Binding TotalDebit}" />
<TextBlock Margin="30, 0, 30, 0" Text="{Binding TotalCredit}" />
</StackPanel>
<DataGrid ItemsSource="{Binding Items}" />
</DockPanel>
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Windows;namespace WpfApp1
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent(); var r = new Random();
var testData = Enumerable.Range(1, 7).Select(i => new Voucher()
{
No = 145+i,
Date = DateTime.Now.AddDays(r.Next(-5, 5)),
Type = (AccountType)r.Next(2),
Debit = r.Next(100),
Credit = r.Next(100),
});
this.DataContext = new Vouchers(testData);
}
} public class Vouchers : ObservableObject
{
public Vouchers(IEnumerable<Voucher> items)
{
Items = new ObservableCollection<Voucher>(items);
Items.CollectionChanged += (s, e)=> CalcTotals();
Items.ToList().ForEach(item => item.PropertyChanged += (s, e) => CalcTotals());
CalcTotals();
} public ObservableCollection<Voucher> Items { get; private set; } void CalcTotals()
{
TotalCredit = Items.Sum(x => x.Credit);
TotalDebit = Items.Sum(x => x.Debit);
} private decimal _totalDebit;
public decimal TotalDebit
{
get { return _totalDebit; }
set { _totalDebit = value; OnPropertyChanged("TotalDebit"); }
} private decimal _totalCredit;
public decimal TotalCredit
{
get { return _totalCredit; }
set { _totalCredit = value; OnPropertyChanged("TotalCredit"); }
}
}
public enum AccountType { FinancialAccount, OtherAccount }
public class Voucher : ObservableObject
{
public int No { get; set; }
public DateTime Date { get; set; }
public AccountType Type { get; set; }
public string Account { get; set; }
public string Memo { get; set; }
private decimal _debit;
public decimal Debit
{
get { return _debit; }
set { _debit = value; OnPropertyChanged("Debit"); }
} private decimal _credit;
public decimal Credit
{
get { return _credit; }
set { _credit = value; OnPropertyChanged("Credit"); }
}
} public class ObservableObject : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}