Q082. XamDataGrid でフィルタリングの初期値を設定するには?

A.RecordFilter の新しいインスタンスを作成し、FieldLayout.RecordFilters に追加します。


以下、サンプルです。このサンプルでは nameフィールドのフィルタリング条件を「等しい」にし、初期値を「佐藤 陽一」に設定してます。



C#

using System;
using System.Windows;
using Infragistics.Windows.Controls;
using Infragistics.Windows.DataPresenter;

namespace WpfApplication1 {
	public partial class MainWindow : Window {
		public MainWindow() {
			InitializeComponent();
		}

		private void Window_ContentRendered(object sender, EventArgs e) {
			var filter = new RecordFilter();
			filter.FieldName = "name";
			filter.Conditions.Add(new ComparisonCondition(ComparisonOperator.Equals, "佐藤 陽一"));
			this.xamDataGrid1.FieldLayouts[0].RecordFilters.Add(filter);
		}
	}
}


VB.NET

Imports Infragistics.Windows.Controls
Imports Infragistics.Windows.DataPresenter

Public Class MainWindow
	Inherits Window

	Private Sub Window_ContentRendered(sender As System.Object, e As System.EventArgs) Handles Me.ContentRendered
		Dim filter = New RecordFilter()
		filter.FieldName = "name"
		filter.Conditions.Add(New ComparisonCondition(ComparisonOperator.Equals, "佐藤 陽一"))
		Me.xamDataGrid1.FieldLayouts(0).RecordFilters.Add(filter)
	End Sub
End Class
<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:igDP="http://infragistics.com/DataPresenter" 
        xmlns:igWindows="http://infragistics.com/Windows"
        Title="MainWindow" Height="320" Width="540"
        WindowStartupLocation="CenterScreen" ContentRendered="Window_ContentRendered">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="8" />
            <ColumnDefinition />
            <ColumnDefinition Width="8" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="8" />
            <RowDefinition Height="30" />
            <RowDefinition Height="4" />
            <RowDefinition />
            <RowDefinition Height="8" />
        </Grid.RowDefinitions>
        <igDP:XamDataGrid Name="xamDataGrid1" Grid.Column="1" Grid.Row="3" BindToSampleData="True" >
            <igDP:XamDataGrid.FieldSettings>
                <igDP:FieldSettings AllowRecordFiltering="True" />
            </igDP:XamDataGrid.FieldSettings>
        </igDP:XamDataGrid>
    </Grid>
</Window>


WPF FAQ の目次に戻る