PC Review


Reply
Thread Tools Rate Thread

checkbox ListView that will only allow one checked item

 
 
sklett
Guest
Posts: n/a
 
      25th Apr 2007
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


 
Reply With Quote
 
 
 
 
=?Utf-8?B?U2l2YSBN?=
Guest
Posts: n/a
 
      25th Apr 2007
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
>
>
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Listview checked item avi Microsoft Excel Programming 0 23rd Jun 2009 04:12 PM
How can I execute a Sub with the value/text of every checked item inthe ListView? iDesmet Microsoft VB .NET 3 22nd Nov 2008 09:10 PM
Double-Click the listview item with checkbox YXQ Microsoft VB .NET 1 16th Sep 2008 03:03 PM
listview checked item spowel4 Microsoft VB .NET 4 30th Aug 2007 03:24 AM
In the ItemCheck handler of a checked ListView, how to find the Item.text value of the row whose checked value changed? sherifffruitfly Microsoft C# .NET 3 29th Oct 2006 01:49 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:08 PM.