Xceed DataGrid for WPF v7.3 Documentation
Xceed.Wpf.DataGrid Assembly / Xceed.Wpf.DataGrid Namespace / DataGridCollectionViewSourceBase Class / Source Property
Example


In This Topic
    Source Property (DataGridCollectionViewSourceBase)
    In This Topic
    Gets or sets the collection from which the view is created.
    Syntax
    'Declaration
     
    Public Shadows Property Source As Object
    'Usage
     
    Dim instance As DataGridCollectionViewSourceBase
    Dim value As Object
     
    instance.Source = value
     
    value = instance.Source
    public new object Source {get; set;}

    Property Value

    An object representing the collection from which the view is created. By default, a null reference (Nothing in Visual Basic).
    Example
    All examples in this topic assume that the grid is bound to the Orders table of the Northwind database, unless stated otherwise.
    This first code example demonstrates how to create a connection to the Access version of the Northwind database and create a property named Orders to which the grid will be bound. The code should be placed in the App.xaml.vb file.This first code example demonstrates how to create a connection to the Access version of the Northwind database and create a property named Orders to which the grid will be bound. The code should be placed in the App.xaml.cs file.The next example demonstrates how to bind a grid to the Orders table, which is retrieved through the Orders property implemented in the code above.
    Imports System.Data.OleDb
    Imports System.Data
    Shared Sub New()
      Dim dataSet As New DataSet()
      Dim mdbfile As String = "Data\Northwind.mdb"
      Dim connString As String = String.Format("Provider=Microsoft.Jet.OLEDB.4.0; Data Source={0}", mdbfile)
      Dim conn As New OleDbConnection(connString)
      Dim adapter As New OleDbDataAdapter()
    
      adapter.SelectCommand = New OleDbCommand("SELECT * FROM Orders;", conn)
      adapter.Fill(dataSet, "Orders")
      m_orders = dataSet.Tables("Orders")
    End Sub
    
    Public Shared Readonly Property Orders() As DataTable
      Get
        Return m_orders
      End Get
    End Property
    Private Shared m_orders As DataTable
    using System.Data.OleDb;
    using System.Data;
    
    Static App()
    {
      DataSet dataSet = New DataSet();
      string mdbFile = @"Data\Northwind.mdb";
      string connString = String.Format( "Provider=Microsoft.Jet.OLEDB.4.0; Data Source={0}", mdbFile );
    
      OleDbConnection conn = New OleDbConnection( connString );
      OleDbDataAdapter adapter = New OleDbDataAdapter();
    
      adapter.SelectCommand = New OleDbCommand( "SELECT * FROM Orders;", conn );
      adapter.Fill( dataSet, "Orders" );
    
      m_orders = dataSet.Tables[ "Orders" ];
    }
    
    public static DataTable Orders
    {
      get
      {
         return m_orders;
      }
    }
    
    private static DataTable m_orders;
    <Grid xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid"> 
      <Grid.Resources>        
      <xcdg:DataGridCollectionViewSource x:Key="cvs_orders" 
                                      Source="{Binding Source={x:Static Application.Current}, 
                                                          Path=Orders}"/> 
      </Grid.Resources> 
      <xcdg:DataGridControl x:Name="OrdersGrid" 
                            ItemsSource="{Binding Source={StaticResource cvs_orders}}"/> 
    </Grid>
    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