ListViewBase.SelectRange(ItemIndexRange) Method

Definition

Selects a block of items described by the ItemIndexRange.

C#
public void SelectRange(ItemIndexRange itemIndexRange);

Parameters

itemIndexRange
ItemIndexRange

Information about the range of items, including the index of the first and last items in the range, and the number of items.

Examples

Here's how to select the first 9 items in a ListView named itemListView.

C#
if (itemListView.SelectionMode == ListViewSelectionMode.Multiple ||
    itemListView.SelectionMode == ListViewSelectionMode.Extended)
{
    itemListView.SelectRange(new ItemIndexRange(0, 9));
}

Remarks

SelectRange and DeselectRange provide a more efficient way to modify the selection than using the SelectedItems property. When you select items using index ranges, use the SelectedRanges property to get all selected ranges in the list.

When you call SelectRange, all items in the specified range are selected, regardless of their original selection state. You can select all items in a collection by using an ItemIndexRange with a FirstIndex value of 0 and a Length value equal to the number of items in the collection.

Warning

Call the SelectRange method only when the SelectionMode property is set to Multiple or Extended. If you call SelectRange when the SelectionMode is Single or None, an exception is thrown.

Note

If the ItemsSource implements IItemsRangeInfo, the SelectedItems collection is not updated based on selection in the list. Use the SelectedRanges property instead.

Applies to

Product Versions
WinRT Build 10240, Build 10586, Build 14383, Build 15063, Build 16299, Build 17134, Build 17763, Build 18362, Build 19041, Build 20348, Build 22000, Build 22621, Build 26100

See also