Version

Selected Property (UltraGrid)

Returns a reference to a Selected object containing collections of all the selected objects in the grid. This property is read-only at run-time. This property is not available at design-time.
Syntax
'Declaration
 
Public ReadOnly Property Selected As Selected
public Selected Selected {get;}
Remarks

The Selected property of the UltraWinGrid is used to work with any of the currently selected items in the grid. It provides access to the Selected object, which contains three collection sub-objects. Each collection holds one type of selected object; there are collections for rows, columns and cells. Whenever an UltraGridRow, UltraGridColumn or UltraGridCell object in the grid is selected, it is added to the corresponding collection of the Selected object. Deselecting an object removes it from the collection.

You can use the Selected property to iterate through the selected items of any type, or to examine or change the properties of any selected item.

The following sample code copies CustomerID and ContactName fields of all the selected rows to the clipboard as text. It assumes that these fields exist in the table that the selected rows are from and that the rows are not UltraGridGroupByRows.

C#:

            private void button1_Click(object sender, System.EventArgs e)
            {
                Infragistics.Win.UltraWinGrid.SelectedRowsCollection selectedRows;
            
                // Get the selected rows.
                //
                selectedRows = this.ultraGrid1.Selected.Rows;
            
                // If there are no selected rows, return
                //
                if ( selectedRows.Count < 1 )
                        return;
            
                System.Text.StringBuilder sb = new System.Text.StringBuilder( );
            
                // Loop through all the selected rows
                //
                for ( int i = 0; i < selectedRows.Count; i++ )
                {
                        Infragistics.Win.UltraWinGrid.UltraGridRow row;
            
                        row = selectedRows[i];
            
                        // Use Cells collection to get the values for 
                        // CustomerID and ContactName columns.
                        //
                        sb.Append( row.Cells[ "CustomerID" ].Text );
                        sb.Append( "," );
                        sb.Append( row.Cells["ContactName"].Text );
            
                        sb.Append( "\r\n" );
                }
            
                // Copy the text to the clipboard.
                //
                System.Windows.Forms.Clipboard.SetDataObject( sb.ToString( ) );
            }
            
Example
Following code shows some of the information available in AfterSelectChange event. It writes out information on the new selection.

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_AfterSelectChange(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.AfterSelectChangeEventArgs) Handles ultraGrid1.AfterSelectChange

       Debug.Write("AfterSelectChange: ")

       ' Check the type to find out whether rows, columns or cells were seelcted.
       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 Me.ultraGrid1.Selected.Rows.Count = 0 Then
               Debug.WriteLine("No group-by rows selected.")
           Else
               Debug.WriteLine(Me.ultraGrid1.Selected.Rows.Count & " group-by rows 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 Me.ultraGrid1.Selected.Rows.Count = 0 Then
               Debug.WriteLine("No rows selected.")
           Else
               Debug.WriteLine(Me.ultraGrid1.Selected.Rows.Count & " rows 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 Me.ultraGrid1.Selected.Columns.Count = 0 Then
               Debug.WriteLine("Columns are being unselected.")
           Else
               Debug.WriteLine(Me.ultraGrid1.Selected.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 Me.ultraGrid1.Selected.Cells.Count = 0 Then
               Debug.WriteLine("Columns are being unselected.")
           Else
               Debug.WriteLine(Me.ultraGrid1.Selected.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_AfterSelectChange(object sender, Infragistics.Win.UltraWinGrid.AfterSelectChangeEventArgs e)
{

	Debug.Write( "AfterSelectChange: " );

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