![xamGrid Change Child Band Visibility 01.png](images/xamGrid_Change_Child_Band_Visibility_01.png)
Please note that this control has been retired and is now obsolete to the XamDataGrid control, and as such, we recommend migrating to that control. It will not be receiving any new features, bug fixes, or support going forward. For help or questions on migrating your codebase to the XamDataGrid, please contact support.
Using the xamGrid™ control’s ColumnLayoutHeaderVisibility property, you can change the visibility of ChildBand header rows which hold child rows for a particular ColumnLayout. The following table shows the members of the ColumnLayoutHeaderVisibility property.
You will bind ColumnLayoutHeaderVisibility enumeration values to a ComboBox control and use this to change the visibility of the xamGrid control’s ChildBand header rows at runtime.
The following code assumes that you know how to set up your WPF project for the xamGrid control.
Add the following namespace declarations
In XAML:
xmlns:ig=http://schemas.infragistics.com/xaml
In Visual Basic:
Imports System.Reflection Imports Infragistics Imports Infragistics.Controls.Grids
In C#:
using System.Reflection; using Infragistics; using Infragistics.Controls.Grids;
Add a StackPanel along with a ComboBox control to change the visibility of the xamGrid control’s ChildBand header rows.
In XAML:
<StackPanel> <ComboBox x:Name="cmbSelection" Margin="10,10,10,0" SelectionChanged="cmbSelection_SelectionChanged"> </ComboBox> <!-- TODO: Add xamGrid control --> </StackPanel>
In Visual Basic:
Private cmbSelection As ComboBox ' ... InitializeComponent() ' ... Dim sp As New StackPanel() sp.Orientation = Orientation.Vertical cmbSelection = New ComboBox() cmbSelection.Margin = New Thickness(10, 10, 10, 0) AddHandler cmbSelection.SelectionChanged, AddressOf cmbSelection_SelectionChanged sp.Children.Add(cmbSelection) 'TODO Add xamGrid control Me.LayoutRoot.Children.Add(sp) 'TODO Add a method call
In C#:
private ComboBox cmbSelection; // ... InitializeComponent(); // ... StackPanel sp = new StackPanel(); sp.Orientation = Orientation.Vertical; cmbSelection = new ComboBox(); cmbSelection.Margin = new Thickness(10, 10, 10, 0); cmbSelection.SelectionChanged += cmbSelection_SelectionChanged; sp.Children.Add(cmbSelection); //TODO Add xamGrid control this.LayoutRoot.Children.Add(sp); // Add a method call
Add the xamGrid control with the following attributes to the StackPanel.
In XAML:
<ig:XamGrid x:Name="xamGrid" Margin="10" ColumnLayoutHeaderVisibility="Always" ItemsSource="{Binding Source={StaticResource DataToolCars}, Path=CountryCarMakers}"> <ig:XamGrid.PagerSettings> <ig:PagerSettings AllowPaging="None" PageSize="5" /> </ig:XamGrid.PagerSettings> </ig:XamGrid>
In Visual Basic:
Private xamGrid As xamGrid ' ... xamGrid = New XamGrid() xamGrid.Margin = New Thickness(10) xamGrid.ColumnLayoutHeaderVisibility = ColumnLayoutHeaderVisibility.Always xamGrid.PagerSettings.AllowPaging = PagingLocation.None xamGrid.ItemsSource = DataToolCars.CountryCarMakers sp.Children.Add(xamGrid)
In C#:
private xamGrid xamGrid; // ... xamGrid = new XamGrid(); xamGrid.Margin = new Thickness(10); xamGrid.ColumnLayoutHeaderVisibility = ColumnLayoutHeaderVisibility.Always; xamGrid.PagerSettings.AllowPaging = PagingLocation.None; xamGrid.ItemsSource = DataToolCars.CountryCarMakers; sp.Children.Add(xamGrid);
Add the following method to load the ColumnLayoutHeaderVisibility enumeration values.
In Visual Basic:
Private Sub LoadChildBandsVisibilityValues() Dim en As [Enum] = xamGrid.ColumnLayoutHeaderVisibility Dim enumValues As IEnumerable(Of [Enum]) = From f In en.GetType().GetFields(BindingFlags.Static Or BindingFlags.Public) _ Select DirectCast(f.GetValue(en), [Enum]) For Each enums As [Enum] In enumValues cmbSelection.Items.Add("Child Bands Visibility: " & enums.ToString()) Next End Sub
In C#:
private void LoadChildBandsVisibilityValues() { Enum en = xamGrid.ColumnLayoutHeaderVisibility; IEnumerable<Enum> enumValues = from f in en.GetType().GetFields(BindingFlags.Static | BindingFlags.Public) select (Enum)f.GetValue(en); foreach (Enum enums in enumValues) { cmbSelection.Items.Add("Child Bands Visibility: " + enums.ToString()); } }
Add the following method call at the end of the constructor.
In Visual Basic:
InitializeComponent() ' ... LoadChildBandsVisibilityValues()
In C#:
InitializeComponent(); // ... LoadChildBandsVisibilityValues();
Implement the event handler for the ComboBox control’s SelectionChanged event.
In Visual Basic:
Private Sub cmbSelection_SelectionChanged(ByVal sender As Object, ByVal e As SelectionChangedEventArgs) Dim val As ColumnLayoutHeaderVisibility = DirectCast(cmbSelection.SelectedIndex, ColumnLayoutHeaderVisibility) Me.xamGrid.ColumnLayoutHeaderVisibility = val End Sub
In C#:
private void cmbSelection_SelectionChanged(object sender, SelectionChangedEventArgs e) { ColumnLayoutHeaderVisibility val = (ColumnLayoutHeaderVisibility)cmbSelection.SelectedIndex; this.xamGrid.ColumnLayoutHeaderVisibility = val; }
Run the application. The visibility of the xamGrid control’s ChildBand header rows will change whenever you select an item in the ComboBox controls. The following image shows how xamGrid will look like with the ColumnLayoutHeaderVisibility property set to Always.