1
你好我很疲倦开始编码,这是我第一次认真的应用程序。我有一个分组数据网格,我想从列值的各组和添加,使其看起来像这样 https://leeontech.files.wordpress.com/2010/02/final.png如何在数据网格中添加数值总和与分组WPF c#
我尝试使用从互联网上,但没有工作的许多解决方案,对我来说:
我的XML
<DataGrid x:Name="GridRaport" CanUserAddRows="False" VerticalAlignment="Stretch" MinWidth="500" AlternatingRowBackground="LightBlue" AlternationCount="2" Margin="20,20,20,20">
<DataGrid.GroupStyle>
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<StackPanel >
<StackPanel Orientation="Horizontal">
<TextBlock Margin="10,10,10,10" Text="{Binding Name}" FontWeight="Bold" />
<TextBlock Margin="30,10,10,10" Text="{Binding ItemCount, StringFormat=Liczba wycieczek: {0}}" FontWeight="Bold" />
</StackPanel>
<ItemsPresenter />
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</DataGrid.GroupStyle>
</DataGrid>
而且我的身后
private void FillGridRaport()
{
string CmdString = string.Empty;
using (SqlConnection con = new SqlConnection(ConString))
{
CmdString = "Long query";
SqlCommand cmd = new SqlCommand(CmdString, con);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable("Wycieczki");
sda.Fill(dt);
DataView dataView = dt.AsDataView();
BindingListCollectionView cv = CollectionViewSource.GetDefaultView(dataView) as BindingListCollectionView;
PropertyGroupDescription groupDescription1 = new PropertyGroupDescription();
groupDescription1.PropertyName = "Pracownik";
cv.GroupDescriptions.Add(groupDescription1);
GridRaport.ItemsSource = cv;
}
}
代码我会厌倦感谢您的帮助