Version

ItemSelectionChanged Event

Occurs after the contents of the SelectedItems collection has changed.
Syntax
'Declaration
 
Public Event ItemSelectionChanged As ItemSelectionChangedEventHandler
public event ItemSelectionChangedEventHandler ItemSelectionChanged
Event Data

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

PropertyDescription
SelectedItems Returns a reference to the UltraListView control's SelectedItems collection.
Example
The following code sample demonstrates how to handle the UltraListView's ItemSelectionChanging event to prevent items in different groups from being selected, and also how to handle the ItemSelectionChanged event to change the appearance for selected items based on whether multiple items are selected:

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.Win
Imports Infragistics.Win.UltraWinListView


    Private Sub ultraListView1_ItemSelectionChanging(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinListView.ItemSelectionChangingEventArgs) Handles ultraListView1.ItemSelectionChanging

        '	Get a reference to the UltraListView control
        Dim listView As UltraListView = CType(sender, UltraListView)

        '	Get a reference to the last member of the SelectedItems
        '	collection...note that it does not matter which member we use,
        '	we just need any currently selected item
        Dim previousSelectedItem As UltraListViewItem = listView.SelectedItems.Last

        '	Iterate the SelectedItems collection passed through the
        '	event arguments this represents what the contents of the
        '	UltraListView's SelectedItems collection will become if this
        '	event is not canceled.
        If listView.ShowGroups AndAlso Not previousSelectedItem Is Nothing Then

            Dim selectedItem As UltraListViewItem
            For Each selectedItem In e.SelectedItems

                '	If any member of the new SelectedItems collection is
                '	in a different group than the currently selected items,
                '	cancel the event.
                If Not selectedItem.Group Is previousSelectedItem.Group AndAlso _
                    Not e.SelectedItems.First Is e.SelectedItems.Last Then
                    e.Cancel = True
                    Return
                End If
            Next
        End If
    End Sub

    Private Sub ultraListView1_ItemSelectionChanged(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinListView.ItemSelectionChangedEventArgs) Handles ultraListView1.ItemSelectionChanged

        '	Get a reference to the UltraListView control
        Dim listView As UltraListView = CType(sender, UltraListView)

        '	Apply a different appearance based on whether multiple items are selected
        If (e.SelectedItems.Count > 1) Then

            listView.ItemSettings.SelectedAppearance.BackColor = Color.LightBlue
            listView.ItemSettings.SelectedAppearance.BackColor2 = SystemColors.Highlight
            listView.ItemSettings.SelectedAppearance.BackGradientStyle = GradientStyle.Vertical
        Else
            listView.ItemSettings.SelectedAppearance.Reset()
        End If
    End Sub
using Infragistics.Win;
using Infragistics.Win.UltraWinListView;
using System.Diagnostics;


		private void ultraListView1_ItemSelectionChanging(object sender, Infragistics.Win.UltraWinListView.ItemSelectionChangingEventArgs e)
		{
			//	Get a reference to the UltraListView control
			UltraListView listView = sender as UltraListView;

			//	Get a reference to the last member of the SelectedItems
			//	collection...note that it does not matter which member we use,
			//	we just need any currently selected item
			UltraListViewItem previousSelectedItem = listView.SelectedItems.Last;

			//	Iterate the SelectedItems collection passed through the
			//	event arguments; this represents what the contents of the
			//	UltraListView's SelectedItems collection will become if this
			//	event is not canceled.
			if ( listView.ShowGroups && previousSelectedItem != null )
			{
				foreach( UltraListViewItem selectedItem in e.SelectedItems )
				{
					//	If any member of the new SelectedItems collection is
					//	in a different group than the currently selected items,
					//	cancel the event.
					if ( selectedItem.Group != previousSelectedItem.Group &&
						 e.SelectedItems.First != e.SelectedItems.Last )
					{
						e.Cancel = true;
						break;
					}
				}
			}
		}

		private void ultraListView1_ItemSelectionChanged(object sender, Infragistics.Win.UltraWinListView.ItemSelectionChangedEventArgs e)
		{
			//	Get a reference to the UltraListView control
			UltraListView listView = sender as UltraListView;

			//	Apply a different appearance based on whether multiple items are selected
			if ( e.SelectedItems.Count > 1 )
			{
				listView.ItemSettings.SelectedAppearance.BackColor = Color.LightBlue;
				listView.ItemSettings.SelectedAppearance.BackColor2 = SystemColors.Highlight;
				listView.ItemSettings.SelectedAppearance.BackGradientStyle = GradientStyle.Vertical;
			}
			else
				listView.ItemSettings.SelectedAppearance.Reset();
		}
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