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> |