Home Forums WPF controls Xceed DataGrid for WPF GroupStyle

Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #22006 |

    Hi, I would like to style the group “rows” differently than the default style. I am using the following XAML:

    <xcdg:DataGridControl.GroupStyle>
    <GroupStyle>
    <GroupStyle.HeaderTemplate>
    <DataTemplate>
    <TextBlock FontWeight=”Bold” FontSize=”15″
    Text=”{Binding Path=Name}”/>
    </DataTemplate>
    </GroupStyle.HeaderTemplate>
    </GroupStyle>
    </xcdg:DataGridControl.GroupStyle>

    I always get this exception (with no inner exception):

    Cannot add content of type ‘System.Windows.Controls.GroupStyle’ to an object of type ‘System.Collections.ObjectModel.ObservableCollection

    Am I doing something wrong?

    Thanks

    Imported from legacy forums. Posted by M (had 10852 views)

    Xceed Support
    Member
    Post count: 5658

    Hi Marcel,

    Just to clarify your intentions: Do you want to change the way the already existing “GroupHeaderControl” looks? Or are you trying to change the way grouping is displayed?

    I ask the question because the GroupStyle property allow you to use the Microsoft way of handling Grouping, which unfortunately disables the UI Virtualization. While you can achieve some pretty wild layouts using the GroupStyle property, if the amount of data you have is pretty large, this methodology becomes prohibitive (loading time and lag).

    To preserve our grouping virtualization, you need not to set the GroupStyle property but instead style the “GroupHeaderControl” control. You can do so easily by using implicit styles for the class (i.e. <Style TargetType=”{x:Type xcdg:GroupHeaderControl}”/>) in a resource dictionary somewhere above the DataGridControl. You can also provide another DataTemplate for the “Group” class, which will only change the way a group information is displayed…

    You can find our default Styles and Templates in the “Themes” folder of the Xceed DataGrid for WPF folder, as a start point for your customization…

    The Group Default DataTemplate is located in the Common.Resources.xaml file, located in the “Themes\Common” subfolder (3rd element from the top, if my memory is right).

    As for the GroupHeaderTemplate style/template, there are several (for each view and theme) but if you are searching for “TargetType=”local:GroupHeaderControl”, then you should easilly find them.

    If you have any more problems or questions, do not hesitate to repost here…

    Imported from legacy forums. Posted by Marcus [Xceed] (had 868 views)

    Xceed Support
    Member
    Post count: 5658

    Also, you can find an example for changing the GroupHeaderControl’s Template in the <a href=”http://doc.xceedsoft.com/products/XceedWpfDataGrid/Templates.html”>Templates documentation topic</a>

    Imported from legacy forums. Posted by Marcus [Xceed] (had 510 views)

    Xceed Support
    Member
    Post count: 5658

    in example 2

    Imported from legacy forums. Posted by Marcus [Xceed] (had 474 views)

    User (Old forums)
    Member
    Post count: 23064

    The “Group” class styling is what i’m after. What I have is a grid with values that are grouped by type of value. The grid has date columns (Jan – Dec). I want to add a total (sum) of each type of value for each month; in the line that the current group name + (itemCount) appears.

    Does anyone have any suggestions how I can go about doing this?

    Thanks for the help so far.

    Imported from legacy forums. Posted by M (had 585 views)

    Xceed Support
    Member
    Post count: 5658

    The Group class currently doesn’t expose the list of items contained in the group, making impossible “simple” addition like the one you mention…

    This is a limitation we are aware of, and we are planning to address this issue in an upcoming release.

    There is a workaround I could suggest if you absolutely need this feature now, but I have to warn you that is is pretty complex and not necessarily practical.

    Let me know if you still wish to hear it! 😉

    Imported from legacy forums. Posted by Marcus [Xceed] (had 391 views)

    User (Old forums)
    Member
    Post count: 23064

    I have an idea of how to do the summaries, but the layout of the columns could be a problem. I am interested in any code you could provide to help me in the right direction. Some of this is still for demo purposes, so an interim workaround will be appretiated. I could always replace it once the datagrid supports this functionality.

    Thanks
    Marcel

    Imported from legacy forums. Posted by M (had 700 views)

    Xceed Support
    Member
    Post count: 5658

    The workaround I was thinking was something like this:

    The easy way would be:

    – Use reflection to access the “CollectionViewGroup” property on the Group class ( internal property).

    – Use the CollectionViewGroup.Items collection to calculate your statistical data…

    – Display it the way you like…

    This method however requires the ReflectionPermission (usually associated with full trust applications).
    <hr>

    If you need to run in partial trust, the way to obtain the CollectionViewGroup I quickly figured could be something like this:

    – Create a custom RoutedEvent (bubbling), along with custom RoutedEventArgs.

    – The custom routed event would be raised by a custom control, when this one is being loaded or measured for the first time. The control would be hosted within the GroupHeaderControl ControlTemplate or within the Group DataTemplate.

    – The goal of the routed event would be to retrieve the CollectionViewGroup associated with a Group.Value

    – The routed event would then be handled by your window/page. The handler should “browse” the tree of DataGridControl.Items.Groups for a CollectionViewGroup whose “Name” property match the Group.Value contained in the custom RoutedEventArgs. The CollectionViewGroup would be returned in the custom RoutedEventArgs.

    – Once you have the CollectionViewGroup, you can use the CollectionViewGroup.Items collection to calculate your statistical data…

    – Display it the way you like…

    As you can see, the second approach is rather nasty. I truly hope that for the purpose of your demo, you are running in Full Trust…

    Imported from legacy forums. Posted by Marcus [Xceed] (had 479 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks for the pointers – made me think of the problem in a different way. As I have said, our deployment schedule is still 2 to 3 months off, so I’m sure I’ll try the full trust approach first.

    Thanks again.

    BTW: do you guys have any rough estimates on what functionality you will be making available at what time(s) for the foreseable future (next 3 – 4 months)?

    Imported from legacy forums. Posted by M (had 659 views)

    Xceed Support
    Member
    Post count: 5658

    Unfortunately, all the information I can give you at the moment is <a href=”http://forums.xceed.com/forums/ShowPost.aspx?PostID=5917″>this thread</a>.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 566 views)

    User (Old forums)
    Member
    Post count: 23064

    How can I display the items the way I like. I can’t seem to “get at” the group’s display item.

    Do I need to bind the group’s datatemplate to another data source (my new calculated values that I got from the first approach you mentioned)? How can I do this? (I am sure I’m missing something).

    Thanks

    Imported from legacy forums. Posted by M (had 1633 views)

    Xceed Support
    Member
    Post count: 5658

    I’m not sure I understand your questions.

    I think it would help if you could post your XAML experimentations along with a basic explanation of the information you want displayed.

    That way, we can start from that point, and move toward a complete solution.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 446 views)

    User (Old forums)
    Member
    Post count: 23064

    thanks for your help. i will post some code soon.

    Imported from legacy forums. Posted by M (had 675 views)

    User (Old forums)
    Member
    Post count: 23064

    As far as I understand (I could totally be off the mark here), the following xaml from Common.Resource.Xaml binds to the CollectionViewGroup:

    <DataTemplate DataType=”{x:Type xcdg:Group}”>

    <StackPanel Orientation=”Horizontal”>

    <ContentPresenter Content=”{Binding Title}”
    ContentTemplate=”{Binding RelativeSource={RelativeSource TemplatedParent},Path=DataContext.TitleTemplate}”
    ContentTemplateSelector=”{Binding RelativeSource={RelativeSource TemplatedParent},Path=DataContext.TitleTemplateSelector}” />

    <TextBlock Text=”: ” />
    <ContentPresenter Content=”{Binding Value}” />
    <TextBlock Text=” (” />
    <TextBlock Text=”{Binding ItemCount}” />
    <TextBlock Text=”)” />

    </StackPanel>

    </DataTemplate>

    I can get to the items in the CollectionViewGroup to calculate my summaries, but I don’t know what to to with them (my new values). How do I bind to them for each group row so that they are displayed in the datagrid (I have summaries for each column in the grid)?

    I am trying to get to the following view:

    …………………………..COL1..COL2..COL3..COL4
    GROUPROW1
    ….GROUPROW2………sum1..sum2..sum3..sum4…..<– ReadOnly
    ……..ROW1……………val1….val2….val3….val4
    ……..ROW2……………val1….val2….val3….val4
    ……..ROW3……………val1….val2….val3….val4
    ….GROUPROW3………sum1..sum2..sum3..sum4…..<– ReadOnly
    ……..ROW4……………val1….val2….val3….val4
    GROUPROW4
    ….GROUPROW5………sum1..sum2..sum3..sum4…..<– ReadOnly
    ……..ROW6……………val1….val2….val3….val4
    ……..ROW7……………val1….val2….val3….val4

    (Replace the dots with spaces – the forum software doesn’t allow multiple spaces)

    Imported from legacy forums. Posted by M (had 1137 views)

    Xceed Support
    Member
    Post count: 5658

    Hi Marcel,

    It seems that all is missing is to access and display the “summary” information from within the Group Template…

    Imagine something like this (for the Group Template):

    (see code in next post)

    Now, as we mentioned earlier, you have to be aware that we do not have native support for SummaryRows. Therefore, automatic positioning of the summary information (as well as auto-sizing, column re-ordering, … ) is not supported… You would need to do “static” positioning of the Summary Information.

    Dynamic/Automatic positioning of the Summary information is definitely something we are going to push for the SummaryRow feature.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 1802 views)

Viewing 15 posts - 1 through 15 (of 17 total)
  • You must be logged in to reply to this topic.