We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Expand or Collapse the specific Group MVVM

Thread ID:

Created:

Updated:

Platform:

Replies:

129870 Apr 6,2017 10:27 AM Apr 13,2017 04:38 AM WPF 3
loading
Tags: SfDataGrid
Salva
Asked On April 6, 2017 10:27 AM

I have a SfDataGrid with AutoExpandGroups="False"

<syncf:SfDataGrid Grid.Row="0" Grid.Column="0"  x:Name="DataGrid" MinHeight="500"
                              ItemsSource="{Binding Lista}"
                              SelectedItem="{Binding SelectedLista}"
                              AutoGenerateColumns="False"
                              ShowGroupDropArea="False"
                              AllowGrouping="True"
                              AutoExpandGroups="False"
                              AllowFiltering="True"
                              AlternatingRowStyle="{StaticResource AlternatingRowStyle}"
                              SelectionMode="Single"                             
                              SelectionUnit="Row"
                              NavigationMode="Row"
                          >

               <syncf:SfDataGrid.GroupColumnDescriptions>
                    <syncf:GroupColumnDescription ColumnName="nombre" />
                </syncf:SfDataGrid.GroupColumnDescriptions>

               <syncf:SfDataGrid.Columns>
                    <syncf:GridTextColumn MappingName="nombre"
                                      HeaderText="Nombre"
                                      AllowGrouping="True"
                                      GroupMode="Value"
                                      Padding="3,0,3,0"
                                      AllowFiltering="True"
                                      AllowBlankFilters="True" />
                    <syncf:GridTextColumn MappingName="identificador"
                                      HeaderText="Identificador"
                                      Padding="3,0,3,0" />
                    <syncf:GridTextColumn MappingName="nombre"
                                      HeaderText="Programa"
                                      Padding="3,0,3,0" />
     </syncf:SfDataGrid>

I'm using MVVM and I need to Expand a specifc group with MVVM.

Something like this but in MVVM.
var group = (dataGrid.View.Groups[0] as Group);
this.dataGrid.ExpandGroup(group);

this.dataGrid.CollapseGroup(group);

Muthukumar Kalyanasundaram [Syncfusion]
Replied On April 10, 2017 09:08 AM

Hi Salva, 
 
Thank you for contacting Syncfusion support. 
 
We have analyzed your query. If you want to expand and collapse a specific group of record with MVVM pattern, you can achieve your requirement as shown like below code, 
 
Code Snippet: 
 
public static class Commands 
{ 
    static Commands() 
    { 
        CommandManager.RegisterClassCommandBinding(typeof(SfDataGrid), new CommandBinding(ExpandGroup, OnExpandGroup, OnCanExpandCollapse)); 
        CommandManager.RegisterClassCommandBinding(typeof(SfDataGrid), new CommandBinding(CollapseGroup, OnCollapseGroup, OnCanExpandCollapse)); 
    }            
 
    public static RoutedCommand ExpandGroup = new RoutedCommand("ExpandGroup", typeof(SfDataGrid)); 
    public static RoutedCommand CollapseGroup = new RoutedCommand("CollapseGroup", typeof(SfDataGrid)); 
 
    private static void OnExpandGroup(object sender, ExecutedRoutedEventArgs args) 
    { 
        var dataGrid = args.Source as SfDataGrid; 
        var group = (dataGrid.View.Groups[0] as Group); 
        dataGrid.ExpandGroup(group); 
    } 
 
    private static void OnCollapseGroup(object sender, ExecutedRoutedEventArgs args) 
    { 
        var dataGrid = args.Source as SfDataGrid; 
        var group = (dataGrid.View.Groups[0] as Group); 
        dataGrid.CollapseGroup(group); 
    } 
    private static void OnCanExpandCollapse(object sender, CanExecuteRoutedEventArgs e) 
    { 
        e.CanExecute = true; 
    } 
} 
 
 
Please let us know if you have any query. 
 
Regards, 
Muthukumar K 


Salva
Replied On April 12, 2017 11:01 AM

Thanks, In my case, this not solve totally the problem but it have helped to solve it.

To solve it I have used

Command="{Binding ModifyCommand}"
CommandParameter="{Binding ., ElementName=DataGrid}"

And I have all the datagrid in my function.



Muthukumar Kalyanasundaram [Syncfusion]
Replied On April 13, 2017 04:38 AM

Hi Salva,   
 
Thanks for the update. 
 
We are glad that you have fixed your issue. Please let us know if you need any other assistance.   
 
Regards,  
Muthukumar K 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;