Xceed Grid for WinForms v4.3 Documentation
DataSource Property (DetailGrid)
Example 


Xceed.Grid.v4.3 Assembly > Xceed.Grid Namespace > DetailGrid Class : DataSource Property
Gets or sets the data source used to populate the grid's DataRow object.
Syntax
'Declaration
 
<DescriptionAttribute("The data source used to populate the grid.")>

<CategoryAttribute("Data")>

<DefaultValueAttribute("")>

Public Property DataSource As Object
'Usage
 
Dim instance As DetailGrid

Dim value As Object

 

instance.DataSource = value

 

value = instance.DataSource
[Description("The data source used to populate the grid.")]

[Category("Data")]

[DefaultValue("")]

public object DataSource {get; set;}

Property Value

A reference to an object representing the data source to use to populate the grid's DataRow object.
Remarks

If the DataSource contains more than one table, you must set the DataMember property to a string that represents the name of the table to bind to.

The following is a list of the supported data sources:

System.Data.DataTable Represents one table of in-memory data.
System.Data.DataView Represents a databindable, customized view of a System.Data.DataTable for sorting, filtering, searching, editing, and navigation.
System.Data.DataSet Represents an in-memory cache of data.
System.Data.DataViewManager Contains a default System.Data.DataViewSettingCollection for each System.Data.DataTable in a System.Data.DataSet.
Any component that implements the System.ComponentModel.IListSource interface. Provides functionality to an object to return a list that can be bound to a data source.
Any component that implements the System.Collections.IList interface. Represents a collection of objects that can be individually accessed by index.
Jagged arrays A jagged array is an array whose elements are arrays.

If the data source is a jagged array and rows are added or removed from the jagged array from outside of the grid, then the jagged array must be reassigned to the DataSource property in order for the modifications to be reflected in the grid. If an existing value is changed in the jagged array from outside of the grid, for example the text of one of the elements, in order for the changes to be reflected in the grid, the jagged array can be reassigned to the grid OR the grid's UpdateRectangles method can be called.
Example
The following example demonstrates how to bind the grid to a dataset filled by an ADO data adapter:

The next example demonstrates how to bind the grid to a jagged array:

Imports Xceed.Grid

Imports System.Data.OleDb



Dim connectionString As String = "" 'connection query

Dim connection As New OleDbConnection( connectionString )



connection.Open()



Dim selectQuery As String = "SELECT * FROM Clients"

Dim dataAdapter As New OleDbDataAdapter( selectQuery, connection )

Dim dataSet As New DataSet( "Clients" )



dataAdapter.Fill( dataSet )



gridControl1.DataSource = dataSet.Tables( 0 )
using Xceed.Grid;

using System.Data.OleDb;



string connectionString = ""; //connection query

OleDbConnection connection = new OleDbConnection( connectionString );



connection.Open();



string selectQuery = "SELECT * FROM Clients";

OleDbDataAdapter dataAdapter = new OleDbDataAdapter( selectQuery, connection );

DataSet dataSet = new DataSet( "Clients" );



dataAdapter.Fill( dataSet );



gridControl1.DataSource = dataSet.Tables[ 0 ];
' Create a jagged array

Dim data()() As Object= New Object( 9 )() {

      New Object( 3 ) { "Canada" , 31500000 , "Ottawa" , "12.2 ºc" },

      New Object( 3 ) { "Switzerland" , 7300000, "Bern"  , "23.3 ºc"},

      New Object( 3 ) { "France" , 59500000 , "Paris" , "27.3 ºc" } ,

      New Object( 3 ) { "USA" , 278000000 , "Washington" , "14.1 ºc" } ,

      New Object( 3 ) { "UK" , 59700000, "London" , "23.7 ºc" } ,

      New Object( 3 ) { "Belgium" , 10300000, "Brussels" , "21.8 ºc" } ,

      New Object( 3 ) { "Italy" , 57700000 , "Rome" , "29.6 ºc"} ,

      New Object( 3 ) { "Spain" , 40000000 , "Madrid" , "31.8 ºc" } ,

      New Object( 3 ) { "Germany" , 83000000, "Berlin" , "25.1 ºc" } ,

      New Object( 3 ) { "Japan" , 126800000, "Tokyo" , "17.2 ºc" } }

      

' Assign the jagged array to the DataSource property

gridControl1.DataSource = data      



' Arrange and format the titles of the columns.

Dim nfi As New NumberFormatInfo()

nfi.NumberGroupSeparator = " "



gridControl1.Columns( 1 ).FormatProvider = nfi 

gridControl1.Columns( 1 ).FormatSpecifier = "n0";



gridControl1.Columns( 0 ).Title = "Country"

gridControl1.Columns( 1 ).Title = "Population"

gridControl1.Columns( 2 ).Title = "Capital"

gridControl1.Columns( 3 ).Title = "Average Temperature"
// Create a jagged array

object[][] data= new object[ 10 ][] { 

          new object[ 4 ] { "Canada" , 31500000 , "Ottawa" , "12.2 ºc" },

          new object[ 4 ] { "Switzerland" , 7300000, "Bern"  , "23.3 ºc"},

          new object[ 4 ] { "France" , 59500000 , "Paris" , "27.3 ºc" } ,

          new object[ 4 ] { "USA" , 278000000 , "Washington" , "14.1 ºc" } ,

          new object[ 4 ] { "UK" , 59700000, "London" , "23.7 ºc" } ,

          new object[ 4 ] { "Belgium" , 10300000, "Brussels" , "21.8 ºc" } ,

          new object[ 4 ] { "Italy" , 57700000 , "Rome" , "29.6 ºc"} ,

          new object[ 4 ] { "Spain" , 40000000 , "Madrid" , "31.8 ºc" } ,

          new object[ 4 ] { "Germany" , 83000000, "Berlin" , "25.1 ºc" } ,

          new object[ 4 ] { "Japan" , 126800000, "Tokyo" , "17.2 ºc" } };

                                  

// Assign the jagged array to the DataSource property                            

gridControl1.DataSource = data;



// Arrange and format the titles of the columns.

NumberFormatInfo nfi = new NumberFormatInfo();

nfi.NumberGroupSeparator = " ";



gridControl1.Columns[1].FormatProvider = nfi ;

gridControl1.Columns[1].FormatSpecifier = "n0" ;



gridControl1.Columns[0].Title = "Country";

gridControl1.Columns[1].Title = "Population";

gridControl1.Columns[2].Title = "Capital";

gridControl1.Columns[3].Title = "Average Temperature";
Requirements

Target Platforms: 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

Reference

DetailGrid Class
DetailGrid Members
DataMember Property
SetDataBinding Method