Solved

How to check if listview item has been checked

Posted on 2009-07-07
2
426 Views
Last Modified: 2012-05-07
I want to check if a checkbox has been checked in a listview control before proceeding.  if none are checked then I don't want to carry on

foreach (ListViewItem item in lvtest.Items)
        {
}

How can I do this?
0
Comment
Question by:mugsey
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 27

Accepted Solution

by:
VBRocks earned 250 total points
ID: 24794647
       Dim bIsChecked As Boolean = False

        For Each item As ListViewItem In Me.ListView1.Items

            If item.Checked = True Then

                bIsChecked = True
                Exit For

            End If

        Next


        If bIsChecked Then

            'At least one was checked...

        End If

0
 
LVL 33

Assisted Solution

by:Todd Gerbert
Todd Gerbert earned 250 total points
ID: 24794754
This is essentially the same thing VBRocks wrote, but in C#.
bool anyChecked = false;
foreach (ListViewItem item in listView1.Items)
{
	if (item.Checked)
	{
		anyChecked = true;
		break;
	}
}
 
if (anyChecked)
	// Proceed
	;
else
	// None were checked
	MessageBox.Show("You must select at least one item.");

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question