SetDataBinding Method
See Also 
Xceed.Grid Assembly > Xceed.Grid Namespace > GridControl Class : SetDataBinding Method


dataSource
The data source used to populate the grid, typed as System.Object.
dataMember
A string that specifies the table to bind to within the object returned by the DataSource property.
Sets the DataSource and DataMember properties at run time.

Syntax

Visual Basic (Declaration) 
Public Sub SetDataBinding( _
   ByVal dataSource As Object, _
   ByVal dataMember As String _
) 
Visual Basic (Usage)Copy Code
Dim instance As GridControl
Dim dataSource As Object
Dim dataMember As String
 
instance.SetDataBinding(dataSource, dataMember)
C# 
public void SetDataBinding( 
   object dataSource,
   string dataMember
)

Parameters

dataSource
The data source used to populate the grid, typed as System.Object.
dataMember
A string that specifies the table to bind to within the object returned by the DataSource property.

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:

Visual BasicCopy Code
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.SetDataBinding( dataSet, "Clients" )
C#Copy Code
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.SetDataBinding( dataSet, "Clients" );
Visual BasicCopy Code
' Create a jagged array
Dim data()() As Object= New Integer( 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.SetDataBinding( dataSet, Nothing )      

' 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"
C#Copy Code
// 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.SetDataSource( data, null );

// 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";

Remarks

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.

Requirements

Target Platforms: Windows 2000, Windows XP SP3 Family, Windows Server 2003-2008 Family, Windows Vista, Windows 7

See Also