Link to home
Start Free TrialLog in
Avatar of NSing
NSing

asked on

How do I include an event handler to allow only one checkbox in a listview?

What event handler code would I include with the below C# code that would only allow one check box at a time to be checked in the listview?  

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace ToDoListWM5_Live
{
    public partial class DeleteToDoItemsView : UserControl
    {
        private ToDoListDS.ToDoListDataTable viewData;

        private ToDoListDS.ToDoListDataTable viewItemsToDelete;

        //public event ItemCheckEventHandler ItemCheck;
       
        public DeleteToDoItemsView()
        {
            InitializeComponent();
            viewItemsToDelete = new ToDoListDS.ToDoListDataTable();
        }

        public ToDoListDS.ToDoListDataTable ViewItemsToDelete
        {
            get
            {
                viewItemsToDelete.Clear();
                foreach (ListViewItem item in this.listView1.Items)
                {
                    if (item.Checked)
                        viewItemsToDelete.AddToDoListRow(item.Text);
                }
                return viewItemsToDelete;
            }
        }



        public ToDoListDS.ToDoListDataTable ViewData
        {
            set
            {
                viewData = value;
                this.listView1.Items.Clear();
                foreach (ToDoListDS.ToDoListRow row in viewData.Rows)
                {
                    this.listView1.Items.Add(new ListViewItem(row.ToDoListItem));
                }
            }
        }
 
    }
}
ASKER CERTIFIED SOLUTION
Avatar of lazyberezovsky
lazyberezovsky
Flag of Belarus image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of NSing
NSing

ASKER

Thanks!!!  Everything is working perfectly now!
Avatar of NSing

ASKER

The solution was very accurate and it was received in a very timely manner.  Excellent job!!!