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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

SfDatagrid Grouping issue

Thread ID:

Created:

Updated:

Platform:

Replies:

140834 Nov 9,2018 12:01 PM UTC Nov 12,2018 12:48 PM UTC WPF 1
loading
Tags: SfDataGrid
Vinay
Asked On November 9, 2018 12:01 PM UTC

I have a SfDatagrid. For different items in combobox placed outside SfDataGrid, SfDataGrid populates different data. So for a particular item in combobox say CLT_Attribute, I want to allow grouping in SfDataGrid and for other combobox items, Grouping should not be allowed in same SfDataGrid. And 
I don't want user to drop columns into drop area and do grouping. I want to group them programatically with selected columns. As soon as I select a particular item CLT_Attribute in combobox,
I want to show SfDatagrid with grouped items. Can you please help me with this issue?

Deivaselvan Y [Syncfusion]
Replied On November 12, 2018 12:48 PM UTC

Hi Vinay, 

We have analyzed your requirement to change Itemsource based on ComboBox item and Allow grouping to particular ComboBox item only. We have prepared sample based on ComboBox.SelectionChanged event as like below code snippet 

private void OnSelectionChanged(object obj) 
{ 
     var objectArray = (object[])obj; 
     var dataGrid = objectArray[0] as SfDataGrid; 
     var comboBox = objectArray[1] as ComboBox; 
     dataGrid.ShowGroupDropArea = false; 
     dataGrid.AutoExpandGroups = false; 
     var itemsSource = (dataGrid.DataContext as ViewModel).EmployeeDetails; 
 
     if (comboBox != null) 
     { 
         var employeelist = new ObservableCollection<Model>(); 
         var selectedItem = comboBox.SelectedValue; 
         switch (selectedItem.ToString()) 
         { 
             //Itemsource for which grouping is applied. 
             case "ItemsSource1": 
             { 
                 employeelist.Add(new Model { EmployeeID = 101, EmployeeName = "Jacobs", EmployeeAge = 25, EmployeeSalary = 20000 }); 
                 employeelist.Add(new Model { EmployeeID = 102, EmployeeName = "Edison", EmployeeAge = 32, EmployeeSalary = 21000 }); 
                 employeelist.Add(new Model { EmployeeID = 103, EmployeeName = "Markswille", EmployeeAge = 45, EmployeeSalary = 22000 }); 
                 employeelist.Add(new Model { EmployeeID = 104, EmployeeName = "Antony", EmployeeAge = 26, EmployeeSalary = 23000 }); 
                 employeelist.Add(new Model { EmployeeID = 105, EmployeeName = "Bergius", EmployeeAge = 29, EmployeeSalary = 24000 }); 
                 dataGrid.AutoExpandGroups = true; 
                 dataGrid.ItemsSource = employeelist; 
                 dataGrid.GroupColumnDescriptions.Add(new GroupColumnDescription() { ColumnName = "EmployeeID" }); 
                 break; 
             } 
             case "ItemsSource2": 
             { 
                 employeelist.Add(new Model { EmployeeID = 111, EmployeeName = "Jacobs", EmployeeAge = 25, EmployeeSalary = 20000 }); 
                 employeelist.Add(new Model { EmployeeID = 112, EmployeeName = "Edison", EmployeeAge = 32, EmployeeSalary = 21000 }); 
                 employeelist.Add(new Model { EmployeeID = 113, EmployeeName = "Markswille", EmployeeAge = 45, EmployeeSalary = 22000 }); 
                 employeelist.Add(new Model { EmployeeID = 114, EmployeeName = "Antony", EmployeeAge = 26, EmployeeSalary = 23000 }); 
                 employeelist.Add(new Model { EmployeeID = 115, EmployeeName = "Bergius", EmployeeAge = 29, EmployeeSalary = 24000 }); 
                 goto default; 
              } 
              case "ItemsSource3": 
              { 
                   employeelist.Add(new Model { EmployeeID = 121, EmployeeName = "Jacobs", EmployeeAge = 25, EmployeeSalary = 20000 }); 
                   employeelist.Add(new Model { EmployeeID = 122, EmployeeName = "Edison", EmployeeAge = 32, EmployeeSalary = 21000 }); 
                   employeelist.Add(new Model { EmployeeID = 123, EmployeeName = "Markswille", EmployeeAge = 45, EmployeeSalary = 22000 }); 
                   employeelist.Add(new Model { EmployeeID = 124, EmployeeName = "Antony", EmployeeAge = 26, EmployeeSalary = 23000 }); 
                   employeelist.Add(new Model { EmployeeID = 125, EmployeeName = "Bergius", EmployeeAge = 29, EmployeeSalary = 24000 }); 
                   goto default;       
               } 
               default: 
               { 
                    dataGrid.ItemsSource = employeelist; 
                    break; 
               } 
          } 
     } 
} 


<ComboBox x:Name="comboBox" ItemsSource="{Binding ItemsSourceList}"> 
   <interactivity:Interaction.Triggers> 
       <interactivity:EventTrigger EventName="SelectionChanged"> 
          <interactivity:InvokeCommandAction Command="{Binding SelectionChanged}" > 
              <interactivity:InvokeCommandAction.CommandParameter> 
                  <MultiBinding Converter="{StaticResource multiConverter}"> 
                       <Binding ElementName="sfdatagrid" /> 
                       <Binding ElementName="comboBox" /> 
                  </MultiBinding> 
               </interactivity:InvokeCommandAction.CommandParameter> 
          </interactivity:InvokeCommandAction> 
      </interactivity:EventTrigger> 
   </interactivity:Interaction.Triggers> 
</ComboBox> 

Please find the sample from the below link. 

Please let us know if you have any other questions.

Regards, 
Deivaselvan 


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.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon 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.Close Icon

;