[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How to check if listview item has been checked

Posted on 2009-07-07
2
Medium Priority
?
432 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

650 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