Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6175081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:51:47+00:00 2026-05-23T23:51:47+00:00

I’m using a ListCollectionView as an ItemsSource for a WPF DataGrid. I want the

  • 0

I’m using a ListCollectionView as an ItemsSource for a WPF DataGrid.

I want the user to be able to add columns to group by, and I’m using the following as the GroupStyle:

<DataGrid.GroupStyle>
    <GroupStyle>
        <GroupStyle.ContainerStyle>
            <Style TargetType="{x:Type GroupItem}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type GroupItem}">
                            <Expander>
                                <Expander.Header>
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Text="Group Name: "/>
                                        <TextBlock Text="{Binding Path=Name}" FontWeight="Bold"/>
                                        <TextBlock Text=" "/>
                                        <TextBlock Text="{Binding Path=ItemCount}" FontStyle="Italic"/>
                                        <TextBlock Text=" Items" FontStyle="Italic"/>
                                    </StackPanel>
                                </Expander.Header>
                                <ItemsPresenter>

                                </ItemsPresenter>
                            </Expander>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </GroupStyle.ContainerStyle>
    </GroupStyle>
</DataGrid.GroupStyle>

My problem is that when there is more then 1 column in the GroupDescriptions, then group headings are displayed without indentation. Another problem is that I would like the TextBox that has “Group Name:” to bind to the Column name that is grouping that level – So if I’m groupint at that level on column = Gender it would say “Gender: “.

So how can I indent the group heading according to its nesting level in the GroupDescriptions collection, and how can I bind to the Column name?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T23:51:50+00:00Added an answer on May 23, 2026 at 11:51 pm

    No one stepped up to this, so with a lot of tinkering, I came up with the following solution. I created a multi value converter, taking the current CollectionViewGroup, the whole ListCollectionView and the DataGrid as parameters.

    Public Class GroupLevelConverter
        Implements IMultiValueConverter
    
        Public Function Convert(values() As Object, targetType As System.Type,
                                parameter As Object, culture As System.Globalization.CultureInfo
                                ) As Object Implements System.Windows.Data.IMultiValueConverter.Convert
            If TypeOf values(0) Is CollectionViewGroup Then
                Dim level As Integer = 0
                Dim parent As CollectionViewGroup = values(0)
                Do While parent IsNot Nothing
                    parent = GetParent(values(0))
                    values(0) = parent
                    If parent IsNot Nothing Then
                        level += 1
                    End If
                Loop
                Dim s As String = ""
                For i = 1 To level - 1
                    s += "    "
                Next
                Dim lcv As ListCollectionView = DirectCast(values(1), ListCollectionView)
                Dim pgd As System.Windows.Data.PropertyGroupDescription = lcv.GroupDescriptions(level - 1)
                Dim dg As DataGrid = values(2)
                Dim GroupHeader As String = pgd.PropertyName
                For c = 0 To dg.Columns.Count - 1
                    If dg.Columns(c).SortMemberPath = GroupHeader Then
                        GroupHeader = dg.Columns(c).Header
                        Exit For
                    End If
                Next
                s = s & GroupHeader & ": "
                Return (s)
            End If
            Return ""
    
        End Function
    
        Public Function ConvertBack(value As Object, targetTypes() As System.Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object() Implements System.Windows.Data.IMultiValueConverter.ConvertBack
            Throw New NotSupportedException("Not implemented")
        End Function
    
        Friend Function GetParent(currentViewGroup As CollectionViewGroup) As CollectionViewGroup
            Dim parent As CollectionViewGroup
            Try
                parent = TryCast(currentViewGroup.[GetType]().GetProperty("Parent", System.Reflection.BindingFlags.GetProperty Or
                                                                                                    System.Reflection.BindingFlags.Instance Or
                                                                                                    System.Reflection.BindingFlags.NonPublic).GetValue(currentViewGroup, Nothing), 
                                                                      CollectionViewGroup)
            Catch ex As Exception
                Return Nothing
            End Try
            Return parent
        End Function
    End Class
    

    The CollectionViewGroup is used to find its parent with the GetParent function. This is the non-elegant part of the solution as it relies on capturing an error. The function is called until the error indicates reaching the top group.

    ListCollectionView is used to get the sort column, and the DataGrid to get the more friendly Column Header.

    HTH someone looking at a similar problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.