Xceed Toolkit Plus for WPF v5.1 Documentation
Xceed.Wpf.DataGrid.Toolkit Assembly / Xceed.Wpf.DataGrid Namespace / DataGridVirtualizingQueryableCollectionViewSource Class
Members Example


In This Topic
    DataGridVirtualizingQueryableCollectionViewSource Class
    In This Topic
    The DataGridVirtualizingQueryableCollectionView class and its XAML proxy, the DataGridVirtualizingQueryableCollectionViewSource class, provide support for IQueryable data sources.
    Syntax
    'Declaration
     
    <TypeDescriptionProviderAttribute(MS.Internal.ComponentModel.DependencyObjectProvider)>
    <NameScopePropertyAttribute("NameScope", System.Windows.NameScope)>
    Public Class DataGridVirtualizingQueryableCollectionViewSource 
       Inherits DataGridVirtualizingCollectionViewSourceBase
    [TypeDescriptionProvider(MS.Internal.ComponentModel.DependencyObjectProvider)]
    [NameScopeProperty("NameScope", System.Windows.NameScope)]
    public class DataGridVirtualizingQueryableCollectionViewSource : DataGridVirtualizingCollectionViewSourceBase 
    Example
    The following example demonstrates how to bind to a data source that implements IQueryable (LINQ DataContext) and allow items to be edited, deleted, inserted, and refreshed.
    <Grid xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid">
       <Grid.Resources>
    
    
         <xcdg:DataGridVirtualizingQueryableCollectionViewSource x:Key="cvs_queryableSource"
                                                                 QueryableSource="{Binding Path=QueryableSource}"
                                                                 CommitMode="EditCommitted"
                                                                 CreatingNewItem="DataGridVirtualizingQueryableCollectionViewSource_CreatingNewItem"
                                                                 CommittingNewItem="DataGridVirtualizingQueryableCollectionViewSource_CommittingNewItem"
                                                                 CancelingNewItem="DataGridVirtualizingQueryableCollectionViewSource_CancelingNewItem"
                                                                 CommitItems="DataGridVirtualizingQueryableCollectionViewSource_CommitItems"
                                                                 RemovingItem="DataGridVirtualizingQueryableCollectionViewSource_RemovingItem" />
       </Grid.Resources>
    
       <xcdg:DataGridControl ItemsSource="{Binding Source={StaticResource cvs_queryableSource}}"
                             ItemScrollingBehavior="Deferred"
                             MaxGroupLevels="2"
                             MaxSortLevels="2"
                             IsDeleteCommandEnabled="True"
                             IsRefreshCommandEnabled="True">
          <xcdg:DataGridControl.Resources>
    
             <Style TargetType="{x:Type xcdg:Row}"
                    x:Key="RowHeightStyle">
                <Setter Property="Height"
                        Value="27" />
             </Style>
    
             <Style TargetType="{x:Type xcdg:DataRow}"
                    BasedOn="{StaticResource RowHeightStyle}" />
             <Style TargetType="{x:Type xcdg:InsertionRow}"
                    BasedOn="{StaticResource RowHeightStyle}" />
          </xcdg:DataGridControl.Resources>
    
          <xcdg:DataGridControl.View>
             <xcdg:TableView>
                <xcdg:TableView.FixedHeaders>
                   <DataTemplate>
                      <xcdg:InsertionRow />
                   </DataTemplate>
                </xcdg:TableView.FixedHeaders>
             </xcdg:TableView>
          </xcdg:DataGridControl.View>
    
          <xcdg:DataGridControl.Columns>
             <xcdg:Column FieldName="ProductID"
                          AllowSort="False"
                          AllowGroup="False" />
          </xcdg:DataGridControl.Columns>
       </xcdg:DataGridControl>
    </Grid>
    The following code provides the code-behind implementation of the CommitMode, CreatingNewItem, CommittingNewItem, CancelingNewItem, CommitItems, and RemovingItem events.
    Public Partial Class Window1
                         Inherits Window
      Public Sub New
        Me.DataContext = Me
        InitializeComponent()
      End Sub
    
      ' QUERYABLE SOURCE
      Public Readonly Property QueryableSource As IQueryable
        Get
          If m_queryable Is Nothing Then
            m_northwind = New NorthwindDataContext()
            m_queryable = m_northwind.Products
          End If
          Return m_queryable
        End Get
      End Property
    
      Private m_northwind As NorthwindDataContext
      Private m_queryable As IQueryable
    
      ' QUERYABLE INSERTION SUPPORT
      Private Sub DataGridVirtualizingQueryableCollectionViewSource_CreatingNewItem( sender As Object, e As DataGridCreatingNewItemEventArgs )
        Dim productToInsert As New Product()
        e.NewItem = productToInsert
        m_northwind.Products.InsertOnSubmit( productToInsert )
        e.Handled = True
      End Sub
    
      Private Sub DataGridVirtualizingQueryableCollectionViewSource_CommittingNewItem( sender As Object, e As DataGridCommittingNewItemEventArgs )
        Try
          m_northwind.SubmitChanges()
        Catch e As Exception
          e.Cancel = True
        End Try
        e.Handled = True
      End Sub
    
      Private Sub DataGridVirtualizingQueryableCollectionViewSource_CancelingNewItem( sender As Object, e As DataGridItemHandledEventArgs )
        m_northwind.GetChangeSet().Inserts.Clear()
        e.Handled = True
      End Sub
    
      ' QUERYABLE EDIT SUPPORT
      Private Sub DataGridVirtualizingQueryableCollectionViewSource_CommitItems( sender As Object, e As CommitItemsEventArgs )
        Try
          m_northwind.SubmitChanges()
        Catch e As Exception
          m_northwind.GetChangeSet().Updates.Clear()
        Finally
          e.AsyncCommitInfo.EndCommit()
        End Try
      End Sub
    
      ' QUERYABLE DELETE SUPPORT
      Private Sub DataGridVirtualizingQueryableCollectionViewSource_RemovingItem( sender As Object, e As DataGridRemovingItemEventArgs )
        Try
          m_northwind.Products.DeleteOnSubmit( TryCast( e.Item, Product ) )
          m_northwind.SubmitChanges()
        Catch e As Exception
          m_northwind.GetChangeSet().Deletes.Clear()
          e.Cancel = True
        End Try
        e.Handled = True
      End Sub
    End Class
    The following code provides the code-behind implementation of the CommitMode, CreatingNewItem, CommittingNewItem, CancelingNewItem, CommitItems, and RemovingItem events.
    public partial class Window1 : Window
    {
     public Window1()
     {
       this.DataContext = this;
       InitializeComponent();
     }
    
     // QUERYABLE SOURCE
     public IQueryable QueryableSource
     {
       get
       {
         if( m_queryable == null )
         {
           m_northwind = new NorthwindDataContext();
           m_queryable = m_northwind.Products;
         }
         return m_queryable;
       }
     }
    
     private NorthwindDataContext m_northwind;
     private IQueryable m_queryable;
    
     // QUERYABLE INSERTION SUPPORT
     private void DataGridVirtualizingQueryableCollectionViewSource_CreatingNewItem( object sender, DataGridCreatingNewItemEventArgs e )
     {
       Product productToInsert = new Product();
       e.NewItem = productToInsert;
       m_northwind.Products.InsertOnSubmit( productToInsert );
       e.Handled = true;
     }
    
     private void DataGridVirtualizingQueryableCollectionViewSource_CommittingNewItem( object sender, DataGridCommittingNewItemEventArgs e )
     {
       try
       {
         m_northwind.SubmitChanges();
       }
       catch
       {
         e.Cancel = true;
       }
       e.Handled = true;
     }
    
     private void DataGridVirtualizingQueryableCollectionViewSource_CancelingNewItem( object sender, DataGridItemHandledEventArgs e )
     {
       m_northwind.GetChangeSet().Inserts.Clear();
       e.Handled = true;
     }
    
     // QUERYABLE EDIT SUPPORT
     private void DataGridVirtualizingQueryableCollectionViewSource_CommitItems( object sender, CommitItemsEventArgs e )
     {
       try
       {
         m_northwind.SubmitChanges();
       }
       catch
       {
         m_northwind.GetChangeSet().Updates.Clear();
       }
       finally
       {
         e.AsyncCommitInfo.EndCommit();
       }
     }
    
     // QUERYABLE DELETE SUPPORT
     private void DataGridVirtualizingQueryableCollectionViewSource_RemovingItem( object sender, DataGridRemovingItemEventArgs e )
     {
       try
       {
         m_northwind.Products.DeleteOnSubmit( e.Item as Product );
         m_northwind.SubmitChanges();
       }
       catch
       {
         m_northwind.GetChangeSet().Deletes.Clear();
         e.Cancel = true;
       }
       e.Handled = true;
     }
    }
    Inheritance Hierarchy

    System.Object
       System.Windows.Threading.DispatcherObject
          System.Windows.DependencyObject
             System.Windows.Data.CollectionViewSource
                Xceed.Wpf.DataGrid.DataGridCollectionViewSourceBase
                   Xceed.Wpf.DataGrid.DataGridVirtualizingCollectionViewSourceBase
                      Xceed.Wpf.DataGrid.DataGridVirtualizingQueryableCollectionViewSource

    Public Constructors
    Public Fields
     NameDescription
    Public Fieldstatic (Shared in Visual Basic)Identifies the QueryableSource dependency property.  
    Top
    Public Properties
     NameDescription
    Public PropertyGets a value indicating whether the foreign key descriptions are automatically created. (Inherited from Xceed.Wpf.DataGrid.DataGridCollectionViewSourceBase)
    Public Property (Inherited from Xceed.Wpf.DataGrid.DataGridCollectionViewSourceBase)
    Public Property (Inherited from System.Windows.Data.CollectionViewSource)
    Public Property (Inherited from System.Windows.Data.CollectionViewSource)
    Public Property (Inherited from System.Windows.Data.CollectionViewSource)
    Public Property (Inherited from System.Windows.Data.CollectionViewSource)
    Public PropertyGets or sets a value representing when the CommitItems event will be raised. (Inherited from Xceed.Wpf.DataGrid.DataGridVirtualizingCollectionViewSourceBase)
    Public Property (Inherited from Xceed.Wpf.DataGrid.DataGridCollectionViewSourceBase)
    Public PropertyGet or sets the default value of the CalculateDistinctValues property when a DataGridItemProperty has not explicitly set its value. (Inherited from Xceed.Wpf.DataGrid.DataGridCollectionViewSourceBase)
    Public Property (Inherited from System.Windows.DependencyObject)
    Public Property (Inherited from System.Windows.Threading.DispatcherObject)
    Public Property (Inherited from Xceed.Wpf.DataGrid.DataGridCollectionViewSourceBase)
    Public Property

    Gets or sets the mode that indicates when distinct values used by auto-filtering should be updated.

    (Inherited from Xceed.Wpf.DataGrid.DataGridCollectionViewSourceBase)
    Public Property (Inherited from System.Windows.Data.CollectionViewSource)
    Public Property (Inherited from System.Windows.Data.CollectionViewSource)
    Public Property (Inherited from System.Windows.Data.CollectionViewSource)
    Public Property (Inherited from System.Windows.Data.CollectionViewSource)
    Public Property (Inherited from System.Windows.Data.CollectionViewSource)
    Public Property (Inherited from System.Windows.Data.CollectionViewSource)
    Public Property (Inherited from System.Windows.Data.CollectionViewSource)
    Public Property (Inherited from System.Windows.DependencyObject)
    Public Property (Inherited from Xceed.Wpf.DataGrid.DataGridCollectionViewSourceBase)
    Public Property (Inherited from Xceed.Wpf.DataGrid.DataGridCollectionViewSourceBase)
    Public Property (Inherited from System.Windows.Data.CollectionViewSource)
    Public Property (Inherited from System.Windows.Data.CollectionViewSource)
    Public Property (Inherited from System.Windows.Data.CollectionViewSource)
    Public PropertyGets a value representing the maximum amount of items that can be loaded in memory. (Inherited from Xceed.Wpf.DataGrid.DataGridVirtualizingCollectionViewSourceBase)
    Public PropertyGets a value representing the number of items that are contained in each page of data that is loaded in memory. (Inherited from Xceed.Wpf.DataGrid.DataGridVirtualizingCollectionViewSourceBase)
    Public PropertyGets or sets a value representing the percentage from the start or the end of a page that, when accessed, will cause the previous or next page to be queried and the items loaded in memory. (Inherited from Xceed.Wpf.DataGrid.DataGridVirtualizingCollectionViewSourceBase)
    Public PropertyGets the queryable source that will provide the data items.  
    Public Property (Inherited from System.Windows.Data.CollectionViewSource)
    Public PropertyGets or sets the collection from which the view is created. (Inherited from Xceed.Wpf.DataGrid.DataGridCollectionViewSourceBase)
    Public Property (Inherited from System.Windows.Data.CollectionViewSource)
    Top
    Public Methods
    Public Events
     NameDescription
    Public Event (Inherited from Xceed.Wpf.DataGrid.DataGridCollectionViewSourceBase)
    Public Event (Inherited from Xceed.Wpf.DataGrid.DataGridCollectionViewSourceBase)
    Public Event (Inherited from Xceed.Wpf.DataGrid.DataGridCollectionViewSourceBase)
    Public EventRaised when a page of data that contains edited items is about to be released from memory. This event must be handled when dealing with an editable grid. (Inherited from Xceed.Wpf.DataGrid.DataGridVirtualizingCollectionViewSourceBase)
    Public Event (Inherited from Xceed.Wpf.DataGrid.DataGridCollectionViewSourceBase)
    Public Event (Inherited from Xceed.Wpf.DataGrid.DataGridCollectionViewSourceBase)
    Public Event (Inherited from Xceed.Wpf.DataGrid.DataGridCollectionViewSourceBase)
    Public EventRaised when the distinct values need to be refreshed. (Inherited from Xceed.Wpf.DataGrid.DataGridCollectionViewSourceBase)
    Public Event (Inherited from Xceed.Wpf.DataGrid.DataGridCollectionViewSourceBase)
    Public Event (Inherited from Xceed.Wpf.DataGrid.DataGridCollectionViewSourceBase)
    Public Event (Inherited from Xceed.Wpf.DataGrid.DataGridCollectionViewSourceBase)
    Public Event (Inherited from System.Windows.Data.CollectionViewSource)
    Public Event (Inherited from Xceed.Wpf.DataGrid.DataGridCollectionViewSourceBase)
    Public Event (Inherited from Xceed.Wpf.DataGrid.DataGridCollectionViewSourceBase)
    Public Event (Inherited from Xceed.Wpf.DataGrid.DataGridCollectionViewSourceBase)
    Public Event (Inherited from Xceed.Wpf.DataGrid.DataGridCollectionViewSourceBase)
    Public Event (Inherited from Xceed.Wpf.DataGrid.DataGridCollectionViewSourceBase)
    Public Event (Inherited from Xceed.Wpf.DataGrid.DataGridCollectionViewSourceBase)
    Top
    Requirements

    Target Platforms: Windows 11, Windows 10, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

    See Also