Version

Cells Property (Selected)

Returns a reference to a collection of the selected UltraGridCell objects. This property is read-only at run-time. This property is not available at design-time.
Syntax
'Declaration
 
Public ReadOnly Property Cells As SelectedCellsCollection
public SelectedCellsCollection Cells {get;}
Remarks

This property returns a reference to a collection of UltraGridCell objects that can be used to retrieve references to the UltraGridCell objects that are currently selected. You can use this reference to access any of the returned collection's properties or methods, as well as the properties or methods of the objects within the collection.

As cells are selected and deselected, their corresponding UltraGridCell objects are added to and removed from the SelectedCells collection returned by this property. When a cell is selected or deselected, the BeforeSelectChange event is generated.

The Count property of the returned SelectedCells collection can be used to determine the number of cells that either belong to a row or are currently selected.

Example
Following code shows some of the information available in BeforeSelectChange event and its potential uses.

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.UltraWinGrid
Imports System.Diagnostics

   Private Sub UltraGrid1_BeforeSelectChange(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.BeforeSelectChangeEventArgs) Handles ultraGrid1.BeforeSelectChange

       ' BeforeSelectChange gets fired when the user selects rows, columns or cells.
       ' NewSelections property off the passed in event args has the new selection.
       ' Type specifies whether the change in selection was with rows, columns or
       ' cells. This also gives you a chance to cancel the new selection by setting
       ' the Cancel property off the event args. If cancelled, the UltraGrid will go
       ' back to previous selection.

       Debug.Write("BeforeSelectChange: ")

       ' Check the type to find out whether rows, columns or cells were selected.
       If e.Type Is GetType(UltraGridGroupByRow) Then

           ' Item type is a group-by-row so use Rows property off the Selected to access those items.
           If e.NewSelections.Rows.Count = 0 Then
               Debug.WriteLine("Group-by rows are being unselected.")
           Else
               Debug.WriteLine(e.NewSelections.Rows.Count & " group-by rows are being selected.")
           End If

       ElseIf e.Type Is GetType(UltraGridRow) Then

           ' Item type is a row so use Rows property off the Selected to access those items.
           If e.NewSelections.Rows.Count = 0 Then
               Debug.WriteLine("Rows are being unselected.")
           Else
               Debug.WriteLine(e.NewSelections.Rows.Count & " rows are being selected.")
           End If

       ElseIf e.Type Is GetType(UltraGridColumn) Then

           ' Item type is a column so use Columns property off the Selected to access those items.
           If e.NewSelections.Columns.Count = 0 Then
               Debug.WriteLine("Columns are being unselected.")
           Else
               Debug.WriteLine(e.NewSelections.Columns.Count & " columns are being selected.")
           End If

       ElseIf e.Type Is GetType(UltraGridCell) Then

           ' Item type is a cell so use Cells property off the Selected to access those items.
           If e.NewSelections.Cells.Count = 0 Then
               Debug.WriteLine("Columns are being unselected.")
           Else
               Debug.WriteLine(e.NewSelections.Cells.Count & " cells are being selected.")
           End If

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

private void ultraGrid1_BeforeSelectChange(object sender, Infragistics.Win.UltraWinGrid.BeforeSelectChangeEventArgs e)
{

	// BeforeSelectChange gets fired when the user selects rows, columns or cells.
	// NewSelections property off the passed in event args has the new selection.
	// Type specifies whether the change in selection was with rows, columns or
	// cells. This also gives you a chance to cancel the new selection by setting
	// the Cancel property off the event args. If cancelled, the UltraGrid will go
	// back to previous selection.

	Debug.Write( "BeforeSelectChange: " );

	// Check the type to find out whether rows, columns or cells were selected.
	if ( typeof( UltraGridGroupByRow ) == e.Type )
	{
		// Item type is a group-by-row so use Rows property off the Selected to access those items.
		if ( e.NewSelections.Rows.Count == 0 )
			Debug.WriteLine( "Group-by rows are being unselected." );
		else
			Debug.WriteLine( e.NewSelections.Rows.Count + " group-by rows are being selected." );
	} 
	else if ( typeof( UltraGridRow ) == e.Type )
	{
		// Item type is a row so use Rows property off the Selected to access those items.
		if ( e.NewSelections.Rows.Count == 0 )
			Debug.WriteLine( "Rows are being unselected." );
		else
			Debug.WriteLine( e.NewSelections.Rows.Count + " rows are being selected." );
	}
	else if ( typeof( UltraGridColumn ) == e.Type )
	{
		// Item type is a column so use Columns property off the Selected to access those items.
		if ( e.NewSelections.Columns.Count == 0 )
			Debug.WriteLine( "Columns are being unselected." );
		else
			Debug.WriteLine( e.NewSelections.Columns.Count + " columns are being selected." );
	}
	else if ( typeof( UltraGridCell ) == e.Type )
	{
		// Item type is a cell so use Cells property off the Selected to access those items.
		if ( e.NewSelections.Cells.Count == 0 )
			Debug.WriteLine( "Columns are being unselected." );
		else
			Debug.WriteLine( e.NewSelections.Cells.Count + " cells are being selected." );
	}	
									
}
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