Solved

How to check if listview item has been checked

Posted on 2009-07-07
2
422 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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need to Interpret Json in Vb.net ( .net 3.5  framework) 11 50
Windows Universal App 22 58
Display Error Message in Asp.net Modal Validation Partial View 3 38
Put File 6 36
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

734 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