GridView使用

来源:互联网 发布:淘宝钓鱼望远镜 编辑:程序博客网 时间:2024/04/30 20:05

一、定义GridViewStyle
1).定义GridVeiwStyle 

    <s:EditorPage.Resources>
        <s:InvertedBooleanConverter x:Key="InvertedBooleanConverter" />
        <Style x:Key="GridViewStyle" TargetType="{x:Type s:SmartGridView}">
            <Setter Property="AutoGenerateColumns" Value="False" />
            <Setter Property="IsFilteringAllowed" Value="False" />
            <Setter Property="CanUserFreezeColumns" Value="True" />
            <Setter Property="FrozenColumnCount" Value="3" />
            <Setter Property="ShowColumnFooters" Value="True" />
            <Setter Property="ShowGroupPanel" Value="False" />
            <Setter Property="RowIndicatorVisibility" Value="Collapsed" />
        </Style>
    </s:EditorPage.Resources>

2).邦定Stytle 
        <s:SmartGridView 
                         Style="{StaticResource GridViewStyle}"
...>

二、合计

1).记录数、最大值、最小值...
                <s:SmartDataColumn Header="年度" IsReadOnly="True" Width="50" DataMemberBinding="{Binding aYear}">
                    <s:SmartDataColumn.AggregateFunctions>
                        <telerik:CountFunction Caption="筆數:" />
                    </s:SmartDataColumn.AggregateFunctions>
                </s:SmartDataColumn>

//注意:运行时会自动将 CountFunction 的但值放到“筆數:”后面

2).栏目合计
                <s:SmartDataColumn Header="本次收款"

                                   Width="70"
                                   DataFormatString="{}{0:0.00}"
                                   DataMemberBinding="{Binding PayAmt}"
                                   FooterTextAlignment="Right"
                                   TextAlignment="Right">
                    <s:SmartDataColumn.AggregateFunctions>
                        <telerik:SumFunction ResultFormatString="{}{0:0.00}" SourceField="PayAmt" />
                    </s:SmartDataColumn.AggregateFunctions>
                    <s:SmartDataColumn.Footer>
                        <TextBlock Text="{Binding FormattedValue}" FontWeight="Bold" Foreground="Blue" />
                    </s:SmartDataColumn.Footer>
                </s:SmartDataColumn>

三、行加入“操作”按钮

                <s:SmartDataColumn Header="操作" Width="40">
                    <s:SmartDataColumn.CellTemplate>
                        <DataTemplate>
                            <Button Content="付" Click="OnPayClick" />
                        </DataTemplate>
                    </s:SmartDataColumn.CellTemplate>
                </s:SmartDataColumn>


四、强行刷新“合计”

        private void OnPayClick(object sender, RoutedEventArgs e)
        {
            var rowView = (DataRowView)(sender as FrameworkElement).DataContext;
            if (rowView.Row.Field<decimal>("PayAmt") == 0)
            {
                rowView["PayAmt"] = rowView["RemainAmount"];
            }
            else
            {
                rowView["PayAmt"] = 0;
            }

            this.Grid.CalculateAggregates();    //刷新行合計
        }

效果如下图:


原创粉丝点击