Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > Other .NET > Windows Presentation Foundation
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Windows Presentation Foundation Discussion of the beta version of Windows Presentation Foundation "WPF" formerly know as codename "Avalon" as well as the related XAML.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Windows Presentation Foundation section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 22nd, 2007, 05:48 PM
Registered User
Join Date: Apr 2007
Location: Portland, OR, USA.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default CheckBox binding in ListView - Multiple events!

I'm binding a checkbox in a ListView to a boolean column in a DataTable, and catching the Checked & Unchekced events to add & remove rows from the table (this is to create a multi-select, multi-column TreeListView, because the WPF TreeView is so basic).

Here's the strange behavior:

When I handle the Checked event and insert rows, all is well. But after I remove the rows in the Unchecked handler, the next time I click on any CheckBox, I get multiple Checked events, one for each time I handled the Unchecked event! The events are not nested so I can't use a flag to block them.

Any ideas? Here's a code snippet for the Unchecked event handler:

// Remove child rows (rows after current row with Level greater than current row)
private void OnUnChecked(object sender, RoutedEventArgs e)
    e.Handled = true;
    DataRow row = ((DataRowView)((CheckBox)sender).DataContext).Row;

    List<DataRow> rowsToRemove = new List<DataRow>();
    for (int i = table.Rows.IndexOf(row) + 1; i < table.Rows.Count; i++)
        if ((int)table.Rows[i]["Level"] <= (int)row["Level"])


    foreach (DataRow rowToRemove in rowsToRemove)

Reply With Quote
  #2 (permalink)  
Old April 22nd, 2007, 06:39 PM
Registered User
Join Date: Apr 2007
Location: Portland, OR, USA.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

As a workaround, if I handle the Click event for the CheckBox instead of the Checked & Unchecked events, I don't have this problem.

This would appear to be a bug in the ListView - perhaps it is reusing ListViewItems and forgetting to remove Checked event handlers? I forgot to mention that I tried rebinding to the table after removing rows in order to start fresh, but I still got multiple Checked events.

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Binding ComboBox inside ListView problem gunnjamie Windows Presentation Foundation 1 July 17th, 2008 02:13 PM
binding a checkbox ?? msordo VB.NET 2002/2003 Basics 0 April 9th, 2008 05:35 PM
Binding a checkbox that contain Y/N values aad1 C# 1 May 17th, 2006 07:23 PM
Binding a comboBox to update a listView Amethyst1984 VB How-To 2 February 28th, 2006 03:07 PM
Adding a checkbox into a listview?? pauljoy Pro VB 6 0 January 9th, 2006 08:04 AM

All times are GMT -4. The time now is 06:40 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.