473,396 Members | 1,608 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

checkbox ListView that will only allow one checked item

I wasn't sure how to deal with this, but this is what I cam up with. If
possible, I'd like a little feedback if there is a better way to deal with a
situation where changes in an event handler cause the event to fire.

private void listView_AvailableTests_ItemChecked(object sender,
ItemCheckedEventArgs e)
{
listView_AvailableTests.ItemChecked -=
listView_AvailableTests_ItemChecked;

foreach(ListViewItem item in listView_AvailableTests.Items)
{
if(item != e.Item)
{
item.Checked = false;
}
}

listView_AvailableTests.ItemChecked +=
listView_AvailableTests_ItemChecked;
}

The above code works, but it just seems a little "odd" to me for some reason
;0)

Any and all comments are welcome.

Thanks,
Steve
Apr 25 '07 #1
1 7597
Another option:

Have a form level variable of type ListViewItem and set it to null:
private ListViewItem _curItem = null;

In the ItemChecked event, have:
if (_curItem != null)
{
_curItem.Checked = false;
}
_curItem = e.Item;
"sklett" wrote:
I wasn't sure how to deal with this, but this is what I cam up with. If
possible, I'd like a little feedback if there is a better way to deal with a
situation where changes in an event handler cause the event to fire.

private void listView_AvailableTests_ItemChecked(object sender,
ItemCheckedEventArgs e)
{
listView_AvailableTests.ItemChecked -=
listView_AvailableTests_ItemChecked;

foreach(ListViewItem item in listView_AvailableTests.Items)
{
if(item != e.Item)
{
item.Checked = false;
}
}

listView_AvailableTests.ItemChecked +=
listView_AvailableTests_ItemChecked;
}

The above code works, but it just seems a little "odd" to me for some reason
;0)

Any and all comments are welcome.

Thanks,
Steve
Apr 25 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Marta Pia | last post by:
Hello, I have a ListView control with CheckBox = true. What I'd like to do is tick all the check boxes when the items are selected. I've tried to put this on the ListView_SelectIndexChanged...
2
by: Marcelo | last post by:
Greetings! I develop a multiple forms application in Microsoft Visual Studio C++ .NET 2003. I am working with a listView with checkBoxes and an event relative to the clicking of a checkBox in this...
12
by: Dennis | last post by:
I have a form which has a ListView control named ListView1 added at design time. When I add items using the following code, they don't appear in the list view. However, if I create a ListView...
1
by: Joe | last post by:
I set up two columns in listview. I use Add to add items, but how do I access the second column? and add text?
1
by: samoore33 | last post by:
I found this code on MSDN, and it works great. It creates a ListView dynamically and add items to it and all. It is great. I have changed a few of the column names to suit me. Dim listView1 As...
10
by: rn5a | last post by:
All the rows in a DataGrid, including the Header, are accompanied with a CheckBox. I want that when the CheckBox in the Header is checked, then all the CheckBoxes should automatically get checked....
3
by: =?Utf-8?B?QnJldA==?= | last post by:
I am a VB Developer w/ SQL Server experience breaking into web world via the Visual Web Developer Express. I've already set up my data sources to my SQL Server tables and have created a grid view...
1
by: =?Utf-8?B?WVhR?= | last post by:
When double-click the listview item with checkbox (View = Details), the checkbox will be checked or unchecked, how to disable this behavior? thank you.
2
by: zubair1 | last post by:
Hello, i'm in a bit of problem here :( I've been using Checkboxes on my app - but it has been horrible, since my app has alot of checkboxes - over 20-30. But i decided to use checkedlistbox...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.