?
Solved

How to check if listview item has been checked

Posted on 2009-07-07
2
Medium Priority
?
428 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 1000 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 1000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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!
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

764 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