Solved

How to check if listview item has been checked

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now