Udostępnij za pośrednictwem


ListViewBase.SelectRange(ItemIndexRange) Method

Definition

Selects a block of items described by the ItemIndexRange.

void SelectRange(ItemIndexRange const& itemIndexRange);
public void SelectRange(ItemIndexRange itemIndexRange);
function selectRange(itemIndexRange)
Public Sub SelectRange (itemIndexRange As 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.

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

See also