Version

CellDataRequested Event

Fired when data is requested by a control bound to this UltraDataSource for a particular cell and the UltraDataSource doesn't have the cell value.
Syntax
'Declaration
 
Public Event CellDataRequested As CellDataRequestedEventHandler
public event CellDataRequestedEventHandler CellDataRequested
Event Data

The event handler receives an argument of type CellDataRequestedEventArgs containing data related to this event. The following CellDataRequestedEventArgs properties provide information specific to this event.

PropertyDescription
CacheData Specifies whether to cache the data. Default value is true. Set this to false if you want to prevent the UltraDataSource from keeping the data. As a result CellDataRequested event will be fired again the next time the data for the cell is needed.
Column Gets the column.
Data Gets or sets the cell data. Set this property to the cell's value.
Row Gets the row.
Remarks

CellDataRequested event is fired when a control bound to the UltraDataSource requests value for a cell and UltraDataSource doesn't have the cell value. Once the value is provided, UltraDataSource will cache it and this event will not be fired for the cell next time. You can prevent the value from being cached by setting the CellDataRequestedEventArgs.CacheData to false in the event handler.

You can also provide cell values without having to hook into this event by using UltraDataRow.SetCellValue method. Also you can clear the cached value for a cell using ResetCachedValue(Int32) method to cause this event to be fired next time for the cell.

Example
Following sample code demonstrates commonly used properties and events in UltraDataSource object model.

For an overview of how to handle events in Visual Basic or Visual C#, see Event Handlers in Visual Basic and Visual C#. For specific information and code examples illustrating how to consume events in your application, see Consuming Events in the .NET Framework Developer's Guide.

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


    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.UltraGrid1.DataSource = Me.UltraDataSource1

        ' Set the root band key so we can easily refer to it later in various
        ' event handlers.
        '
        Me.UltraDataSource1.Band.Key = "RootBand"

        ' Add three columns to the root band.
        Me.UltraDataSource1.Band.Columns.Add("ID", GetType(Integer))
        Me.UltraDataSource1.Band.Columns.Add("Col0", GetType(Integer))
        Me.UltraDataSource1.Band.Columns.Add("Col1", GetType(String))

        ' Add a child band to the root band.
        Dim childBand As UltraDataBand = Me.UltraDataSource1.Band.ChildBands.Add("ChildBand")

        ' Add two columns to the child band.
        childBand.Columns.Add("ChildCol0", GetType(Double))
        childBand.Columns.Add("ChildCol1", GetType(DateTime))

        ' Set the count on the root rows collection to 100.
        Me.UltraDataSource1.Rows.SetCount(100)

        ' Set the id on the root rows.
        Dim column As UltraDataColumn = Me.UltraDataSource1.Band.Columns("ID")
        Dim i As Integer
        For i = 0 To Me.UltraDataSource1.Rows.Count - 1
            Me.UltraDataSource1.Rows(i)(column) = i
        Next
    End Sub

    Dim random As Random = New Random()

    Private Sub UltraDataSource1_CellDataRequested(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinDataSource.CellDataRequestedEventArgs) Handles UltraDataSource1.CellDataRequested
        ' CellDataRequested is fired for every cell. In CellDataRequested event handler
        '

        ' e.Row property indicates which row and e.Column indicates which column the
        ' cell data is being requested for.
        Dim row As UltraDataRow = e.Row

        If "RootBand" Is e.Column.Band.Key Then

            Select Case e.Column.Key
                Case "Col0"
                    e.Data = Me.random.Next()
                Case "Col1"
                    e.Data = "String " & Me.random.Next()
            End Select

        ElseIf "ChildBand" Is e.Column.Band.Key Then

            Select Case e.Column.Key
                Case "ChildCol0"
                    e.Data = Me.random.NextDouble()
                Case "ChildCol1"
                    e.Data = DateTime.Now.AddDays(Me.random.Next(1000))
            End Select

        End If

        ' If CacheData is set to true, which it is by default, then UltraDataSource
        ' will cache the provided cell value and won't fire CellDataRequested next
        ' time for the cell.
        e.CacheData = True
    End Sub

    Private Sub UltraDataSource1_InitializeRowsCollection(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinDataSource.InitializeRowsCollectionEventArgs) Handles UltraDataSource1.InitializeRowsCollection
        If "ChildBand" Is e.Rows.Band.Key Then
            ' For every parent row, we will have 10 child rows.
            e.Rows.SetCount(10)
        End If
    End Sub
using Infragistics.Shared;
using Infragistics.Win;
using Infragistics.Win.UltraWinDataSource;
using Infragistics.Win.UltraWinGrid;
using System.Diagnostics;


		private void Form1_Load(object sender, System.EventArgs e)
		{
			this.ultraGrid1.DataSource = this.ultraDataSource1;

			// Set the root band key so we can easily refer to it later in various
			// event handlers.
			//
			this.ultraDataSource1.Band.Key = "RootBand";

			// Add three columns to the root band.
			this.ultraDataSource1.Band.Columns.Add( "ID", typeof( int ) );
			this.ultraDataSource1.Band.Columns.Add( "Col0", typeof( int ) );
			this.ultraDataSource1.Band.Columns.Add( "Col1", typeof( string ) );

			// Add a child band to the root band.
			UltraDataBand childBand = this.ultraDataSource1.Band.ChildBands.Add( "ChildBand" );

			// Add two columns to the child band.
			childBand.Columns.Add( "ChildCol0", typeof( double ) );
			childBand.Columns.Add( "ChildCol1", typeof( DateTime ) );

			// Set the count on the root rows collection to 100.
			this.ultraDataSource1.Rows.SetCount( 100 );

			// Set the id on the root rows.
			UltraDataColumn column = this.ultraDataSource1.Band.Columns["ID"];
			for ( int i = 0; i < this.ultraDataSource1.Rows.Count; i++ )
				this.ultraDataSource1.Rows[i][column] = i;
		}

		Random random = new Random( );

		private void ultraDataSource1_CellDataRequested(object sender, Infragistics.Win.UltraWinDataSource.CellDataRequestedEventArgs e)
		{
			// CellDataRequested is fired for every cell.

			// e.Row property indicates which row and e.Column indicates which column the
			// cell data is being requested for.
			UltraDataRow row = e.Row;

			if ( "RootBand" == e.Column.Band.Key )
			{
				switch ( e.Column.Key )
				{
					case "Col0":
						e.Data = this.random.Next( );
						break;
					case "Col1":
						e.Data = "String " + this.random.Next( );
						break;
				}
			}
			else if ( "ChildBand" == e.Column.Band.Key )
			{
				switch ( e.Column.Key )
				{
					case "ChildCol0":
						e.Data = this.random.NextDouble( );
						break;
					case "ChildCol1":
						e.Data = DateTime.Now.AddDays( this.random.Next( 1000 ) );
						break;
				}
			}

			// If CacheData is set to true, which it is by default, then UltraDataSource
			// will cache the provided cell value and won't fire CellDataRequested next
			// time for the cell.
			e.CacheData = true;
		}

		private void ultraDataSource1_InitializeRowsCollection(object sender, Infragistics.Win.UltraWinDataSource.InitializeRowsCollectionEventArgs e)
		{
			if ( "ChildBand" == e.Rows.Band.Key )
			{
				// For every parent row, we will have 10 child rows.
				e.Rows.SetCount( 10 );
			}
		}
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