I am trying to add a checked-box to a listview using C#. Something that seems to be straight forward has stopped me dead for the last few days. All is well until I want to add an event handler to the change of the check box.
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
// more componets....
// more componets.......
// more componets.......
this.listView1.SelectedIndexChanged += new System.EventHandler(this.listView1_SelectedIndexChanged);
this.listView1.ItemChecked += new ItemCheckedEventArgs(this.listView1_ItemCheckChanged);
// more componets....
}
private void listView1_ItemCheckChanged(object sender, System.Windows.Forms.ItemCheckedEventArgs e)
{
ListViewItem item = e.Item as ListViewItem;
if (item != null)
{
if (item.Checked)
{
item.Checked = false;
}
else
{
item.Checked = true;
}
}
}
Aucun commentaire:
Enregistrer un commentaire