Version

DataSource Property (UltraGridBase)

Specifies the source of data for the UltraWinGrid.
Syntax
'Declaration
 
Public Property DataSource As Object
public object DataSource {get; set;}
Remarks

The DataSource property is used to specify the object from which the UltraWinGrid should retrieve and display data. Possible data sources include:

  • DataSet
  • DataTable
  • DataView
  • DataViewManager
  • UltraDataSource
  • Any object that implements IList interface, including ArrayList and Array.
  • Any object

Note: For creating custom data sources you can implement the .NET IList interface on your custom object. However, the IList interface doesn't support notifications for changes in data such as changes in cell values, adding or removing of rows, etc. Therefore if you want to support these operations in your data source then it is recommended that you implement the .NET IBindingList interface, instead, which has support for notifying the bound controls of such changes. Other interfaces that may be of interest are the .NET ITypedList and IEditableObject interfaces. Please consult the .NET Framework help for more information on these interfaces.

Setting DataSource or DataMember will cause the control to synchronously load the data source. Therefore if you need to set both of these at run-time, to prevent binding twice, use the SetDataBinding(Object,String,Boolean,Boolean) method instead of setting the individual properties. The SetDataBinding method lets you specify both pieces of information in a single call. Also note that since DataSource, DataMember and SetDataBinding all load the data source, there is no need to call the DataBind method.

If you set up your grid at design time with bands and columns and then bind at run-time to the actual data source, make sure that band and column keys match the names of the corresponding bands (relations) and columns in the actual data source. Otherwise settings on the bands and columns will not be carried over from design time. UltraGrid uses the keys (Key property) of the bands and columns to find matching bands and columns at run-time to copy over the settings from design-time. Therefore it's important to have the design-time band and column keys match the band (relation) and column names in the actual data source.

The same matching process is applied when changing the data source at run-time. The data structure of the control must match the data structure of the newly set data source. The control will automatically create all bands and columns exposed by the new data source. The control will try to maintain the settings on the existing columns and bands assuming that the Key of the Band is the same and that the Key of the column is the same. Columns or bands that do not exist in the new data structure will be destroyed and any new columns or bands in the new data source will be created. There is no way to prevent the the control from automatically picking up the new data structure - it must synchronize it's structure with that of the data source. However, you can make use of the UltraGridLayout.NewBandLoadStyle and UltraGridLayout.NewColumnLoadStyle properties to automatically hide new bands and columns in the new data source. Alternatively you can hide columns or bands by using the Hidden property of the appropriate object. Unbound columns will be maintained, so long as the band the column belongs to is not destroyed.

The InitializeLayout event is raised when the control binds to a DataSource. The InitializeRow event is raied for each row as it's created.

Infragistics.Win.UltraWinGrid.UltraGridLayout.NewBandLoadStyleP:Infragistics.Win.UltraWinGrid.UltraGridLayout.NewColumnLoadStyleP:Infragistics.Win.UltraWinGrid.UltraGridColumn.HiddenP:Infragistics.Win.UltraWinGrid.UltraGridRow.Hidden
Example
Following code sets some of the commonly used properties of the UltraGrid in the Form's Load event.

Imports Infragistics.Shared
Imports Infragistics.Win
Imports Infragistics.Win.UltraWinGrid

  Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

      Me.OleDbDataAdapter1.Fill(Me.DataSet11)
      Me.OleDbDataAdapter2.Fill(Me.DataSet11)
      Me.OleDbDataAdapter3.Fill(Me.DataSet11)

      ' Set the data source and data member to bind the grid.
      Me.UltraGrid1.DataSource = Me.DataSet11
      Me.UltraGrid1.DataMember = ""

      ' Disable alpha-blending which may increase performance.
      Me.UltraGrid1.AlphaBlendEnabled = False

      ' Disable theme support in WinXP based systems.
      Me.UltraGrid1.SupportThemes = False

      ' Set the appearance of the UltraGrid.
      Me.UltraGrid1.DisplayLayout.Appearance.BackColor = Color.Gray

      ' Set the border style of the UltraGrid.
      Me.UltraGrid1.DisplayLayout.BorderStyle = UIElementBorderStyle.InsetSoft

      ' Set the text, appearance and border styles of the caption.
      Me.UltraGrid1.Text = "UltraGrid Caption"
      Me.UltraGrid1.DisplayLayout.CaptionAppearance.FontData.Bold = DefaultableBoolean.True
      Me.UltraGrid1.DisplayLayout.BorderStyleCaption = UIElementBorderStyle.RaisedSoft

      ' Set the update mode which dictates when the UltraGrid calls EndEdit
      ' on IEditableObject row objects.
      Me.UltraGrid1.UpdateMode = UpdateMode.OnRowChangeOrLostFocus

      ' Set the scroll style to Immediate so that the UltraGrid scrolls the rows as
      ' the vertical scroll bar thumb is dragged. Normally the UltraGrid defers the
      ' scrolling until the thumb is released and displays scroll tips instead.
      Me.UltraGrid1.DisplayLayout.ScrollStyle = ScrollStyle.Immediate

  End Sub
using Infragistics.Shared;
using Infragistics.Win;
using Infragistics.Win.UltraWinGrid;
using System.Diagnostics;

private void Form1_Load(object sender, System.EventArgs e)
{

	this.oleDbDataAdapter1.Fill( this.dataSet11 );
	this.oleDbDataAdapter2.Fill( this.dataSet11 );
	this.oleDbDataAdapter3.Fill( this.dataSet11 );

	// Set the data source and data member to bind the grid.
	this.ultraGrid1.DataSource = this.dataSet11;
	this.ultraGrid1.DataMember = "";

	// Disable alpha-blending which may increase performance.
	this.ultraGrid1.AlphaBlendEnabled = false;

	// Disable theme support in WinXP based systems.
	this.ultraGrid1.SupportThemes = false;
	
	// Set the appearance of the UltraGrid.
	this.ultraGrid1.DisplayLayout.Appearance.BackColor = Color.Gray;

	// Set the border style of the UltraGrid.
	this.ultraGrid1.DisplayLayout.BorderStyle = UIElementBorderStyle.InsetSoft;			

	// Set the text, appearance and border styles of the caption.
	this.ultraGrid1.Text = "UltraGrid Caption";
	this.ultraGrid1.DisplayLayout.CaptionAppearance.FontData.Bold = DefaultableBoolean.True;
	this.ultraGrid1.DisplayLayout.BorderStyleCaption = UIElementBorderStyle.RaisedSoft;			
	
	// Set the update mode which dictates when the UltraGrid calls EndEdit
	// on IEditableObject row objects.
	this.ultraGrid1.UpdateMode = UpdateMode.OnRowChangeOrLostFocus;

	// Set the scroll style to Immediate so that the UltraGrid scrolls the rows as
	// the vertical scroll bar thumb is dragged. Normally the UltraGrid defers the
	// scrolling until the thumb is released and displays scroll tips instead.
	this.ultraGrid1.DisplayLayout.ScrollStyle = ScrollStyle.Immediate;

}
Requirements

Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Server 2012, 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