Nader
Nader

Reputation: 13

Listview help..(Windows Forms)

How can I check if no items "At all" selected from listview?

Thanks.

Upvotes: 1

Views: 411

Answers (1)

Winston Smith
Winston Smith

Reputation: 21884

if( myListView.SelectedItems == null || myListView.SelectedItems.Count == 0 )
{
}

See ListView..::.SelectedItems Property for more info.

EDIT: As per the MSDN documentation:

If no items are currently selected, an empty ListView..::.SelectedListViewItemCollection is returned.

So the null check is not needed in this case and you can simply do:

if( myListView.SelectedItems.Count == 0 )
{
}

Upvotes: 7

Related Questions