このコントロールは廃止されたため、XamDataGrid コントロールに移行することをお勧めします。今後、新機能、バグ修正、サポートは提供されません。コードベースの XamDataGrid への移行に関する質問は、サポートまでお問い合わせください。
このセクションは、データ行および xamGrid コントロールの子バンド ヘッダー行を自動展開する方法を示します。
xamGrid コントロールでは、 IsExpanded プロパティを True に設定することによって、データ行および ChildBand ヘッダー行を自動展開することができます。このトピックでは、xamGrid コントロールの RowExpansionChanged イベントを使用して、データ行および ChildBand ヘッダー行を自動展開する方法を示します。
以下のコードは、xamGrid コントロールに WPF プロジェクトを設定する方法を知っていることを前提とします。
以下の名前空間宣言を追加します。
XAML の場合:
xmlns:ig="http://schemas.infragistics.com/xaml"
Visual Basic の場合:
Imports Infragistics.Controls.Grids Imports Infragistics.Controls.Grids.Primitives
C# の場合:
using Infragistics.Controls.Grids; using Infragistics.Controls.Grids.Primitives;
RowExpansionChanged イベントのイベント ハンドラーとともに、xamGrid コントロールを追加し、コントロールの ColumnLayoutHeaderVisibility プロパティを Always に設定します。
XAML の場合:
<ig:XamGrid x:Name="xamGrid" ColumnLayoutHeaderVisibility="Always"
RowExpansionChanged="xamGrid_RowExpansionChanged"
ItemsSource="{Binding Source={StaticResource DataUtil}, Path=CategoriesAndProducts}" />
Visual Basic の場合:
Private xamGrid As XamGrid
' ...
InitializeComponent()
' ...
xamGrid = New XamGrid()
xamGrid.ColumnLayoutHeaderVisibility = ColumnLayoutHeaderVisibility.Always
xamGrid.ItemsSource = DataUtil.CategoriesAndProducts
AddHandler xamGrid.RowExpansionChanged, AddressOf xamGrid_RowExpansionChanged
Me.LayoutRoot.Children.Add(xamGrid)
C# の場合:
private XamGrid xamGrid;
//...
InitializeComponent();
// ...
xamGrid = new XamGrid();
xamGrid.ColumnLayoutHeaderVisibility = ColumnLayoutHeaderVisibility.Always;
xamGrid.RowExpansionChanged += xamGrid_RowExpansionChanged;
xamGrid.ItemsSource = DataUtil.CategoriesAndProducts;
this.LayoutRoot.Children.Add(xamGrid);
Row オブジェクトを自動展開するために以下のメソッドを追加します。
Visual Basic の場合:
Private Sub AutoExpandAllChildRows(ByVal parentRow As Row)
For Each cb As ChildBand In parentRow.ChildBands
cb.IsExpanded = True
If cb.HasChildren Then
AutoExpandAllChildBands(cb)
End If
Next
End Sub
C# の場合:
private void AutoExpandAllChildRows(Row parentRow)
{
foreach (ChildBand cb in parentRow.ChildBands)
{
cb.IsExpanded = true;
if (cb.HasChildren)
AutoExpandAllChildBands(cb);
}
}
ChildBand オブジェクトを自動展開するために以下のメソッドを追加します。
Visual Basic の場合:
Private Sub AutoExpandAllChildBands(ByVal parentBand As ChildBand)
For Each r As Row In parentBand.Rows
r.IsExpanded = True
If r.HasChildren Then
AutoExpandAllChildRows(r)
End If
Next
End Sub
C# の場合:
private void AutoExpandAllChildBands(ChildBand parentBand)
{
foreach (Row r in parentBand.Rows)
{
r.IsExpanded = true;
if (r.HasChildren)
AutoExpandAllChildRows(r);
}
}
Boolean AutoExpanding フラグを追加して、xamGrid コントロールの RowExpansionChanged イベントのイベント ハンドラーを実装します。
Visual Basic の場合:
Private AutoExpanding As Boolean = False
' ...
Private Sub xamGrid_RowExpansionChanged(ByVal sender As System.Object, ByVal e As RowExpansionChangedEventArgs)
If Not AutoExpanding Then
' 親行が展開される場合に限り子行を展開します。
If e.Row.IsExpanded Then
AutoExpanding = True
If (e.Row.RowType = RowType.DataRow) Then
AutoExpandAllChildRows(TryCast(e.Row, Row))
End If
If (e.Row.RowType = RowType.ColumnLayoutHeaderRow) Then
AutoExpandAllChildBands(TryCast(e.Row, ChildBand))
End If
AutoExpanding = False
End If
End If
End Sub
C# の場合:
private bool AutoExpanding = false;
// ...
private void xamGrid_RowExpansionChanged(object sender, RowExpansionChangedEventArgs e)
{
if (!AutoExpanding)
{
// 親行が展開される場合に限り子行を展開します。
if (e.Row.IsExpanded)
{
AutoExpanding = true;
if (e.Row.RowType == RowType.DataRow)
AutoExpandAllChildRows((Row)e.Row);
if (e.Row.RowType == RowType.ColumnLayoutHeaderRow)
AutoExpandAllChildBands((ChildBand)e.Row);
AutoExpanding = false;
}
}
}
アプリケーションを実行します。RowExpansionChanged イベントが発生すると必ず、xamGrid コントロールのすべての子行および ChildBand が自動展開します。