Infragistics2.Win.UltraWinListView.v8.1
SelectedItems Property
See Also  Example
Infragistics.Win.UltraWinListView Namespace > UltraListView Class : SelectedItems Property

Returns a collection of UltraListViewItem objects whose UltraListViewItem.IsSelected property returns true.

Syntax

Visual Basic (Declaration) 
Public ReadOnly Property SelectedItems As UltraListViewSelectedItemsCollection
C# 
public UltraListViewSelectedItemsCollection SelectedItems {get;}

Remarks

By default, selected items are rendered with a background color of SystemColors.Highlight and a foreground color of SystemColors.HighlightText. This provides the end user with a visual cue so that selected items can be easily identified. The UltraListViewItemSettings.SelectedAppearance can be used to customize the visual appearance for selected items.

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.

Visual BasicCopy Code
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
C#Copy Code
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();
       }
    

See Also