Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
DataGrid with totals
Message
From
03/03/2013 18:40:18
 
 
General information
Forum:
ASP.NET
Category:
Windows Presentation Foundation (WPF)
Miscellaneous
Thread ID:
01567310
Message ID:
01567334
Views:
16
>>>>Hi,
>>>>
>>>>in XAML is there a way to add a row of totals to the bottom of a datagrid?
>>>>
>>>>For example I want something like this:
>>>>
>>>>
Invoice #   Invoice Amount
>>>>1234        100.00
>>>>1235        150.00
>>>>2           250.00
>>>>
>>>>where 2 is the count of invoices and 250.00 is the total of the Invoice Amount column.
>>>
>>>I don't think there's an easy way of doing this, certainly not in XAML. If the row content is static (ie not adding, deleting or editing) then it's not too difficult - otherwise, unless you have very strong reasons for doing so, I'd suggest simply showing those values in textblocks below the grid (I think this came up a while back?).
>>>
>>>Alternatively you could look for a third-party grid with this ability - I think DevExpress handle it ?
>>
>>It is on a grid where items can be added, edited and deleted (albeit the editing is done on another tab). If I show them in textblocks below the grid is it easy to change their width and position if somebody rearranges the grid's columns (position and width)?
>
>The sizing is easy enough:
    <StackPanel>
>        <DataGrid CanUserResizeColumns="True" AutoGenerateColumns="True">
>            <DataGrid.Columns>
>                <DataGridTextColumn Header="Column1" x:Name="Column1" Width="100"></DataGridTextColumn>
>                <DataGridTextColumn  Header="Column2" x:Name="Column2" Width="200"></DataGridTextColumn>
>                <DataGridTextColumn  Header="Column3" x:Name="Column3" Width="100"></DataGridTextColumn>
>            </DataGrid.Columns>
>        </DataGrid>
>        <StackPanel Orientation="Horizontal">
>            <TextBlock Background="Red"  Width="{Binding ElementName=Column1,Path=ActualWidth}"></TextBlock>
>            <TextBlock Background="Yellow" Width="{Binding ElementName=Column2,Path=ActualWidth}"></TextBlock>
>            <TextBlock Background="Green"  Width="{Binding ElementName=Column3,Path=ActualWidth}"></TextBlock>
>        </StackPanel>
>    </StackPanel>
but if the user is allowed to change the column order then it would be more difficult (not even sure it's possible). One approach *might* be to use a Grid instead of the horizontal StackPanel and somehow bind the Grid column used by each TextBlock to the Column order of the DataGrid.
>
>Don't suppose you could consider showing the totals in the header instead of a 'footer' ?

hmmm... totals in the header might take a bit of getting used to.

I guess I can define the grid so he users cannot change column order? If so that might at least be a quick way to get this working.

I've found this https://wpfextendeddatagrid.codeplex.com/ which looks like it might do the trick. I'll try it out this week. I would buy a grid like devexpress or telerik's but I've gone bust on this project, what with the coding taking so much longer than I anticipated and having to pay OakLeaf for mentoring services to get me past some hurdles.
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform