checked list view items
-
i have a listview in my program and whenever the item is checked or unchecked i want certain things to happen. how can i accomplish this without the item checked event handler taking over every time i add an item to the listview?
-
i have a listview in my program and whenever the item is checked or unchecked i want certain things to happen. how can i accomplish this without the item checked event handler taking over every time i add an item to the listview?
numbers1thru9 wrote:
i have a listview in my program and whenever the item is checked or unchecked i want certain things to happen. how can i accomplish this without the item checked event handler taking over every time i add an item to the listview?
:wtf: Those statements contradict each other. Unless you mean that the CheckChanged or what ever it's called event is being fired when you add an item to the list view?
Formula 1 - Short for "F1 Racing" - named after the standard "help" key in Windows, it's a sport where participants desperately search through software help files trying to find actual documentation. It's tedious and somewhat cruel, most matches ending in a draw as no participant is able to find anything helpful. - Shog9 Ed
-
numbers1thru9 wrote:
i have a listview in my program and whenever the item is checked or unchecked i want certain things to happen. how can i accomplish this without the item checked event handler taking over every time i add an item to the listview?
:wtf: Those statements contradict each other. Unless you mean that the CheckChanged or what ever it's called event is being fired when you add an item to the list view?
Formula 1 - Short for "F1 Racing" - named after the standard "help" key in Windows, it's a sport where participants desperately search through software help files trying to find actual documentation. It's tedious and somewhat cruel, most matches ending in a draw as no participant is able to find anything helpful. - Shog9 Ed
ok say i have a list of items in the listview, when i either check or uncheck them i want certain things to happen. but if i add an item to the listview, it fires the event handler as if i checked or unchecked an existing item and i want to block it from doing that.
-
i have a listview in my program and whenever the item is checked or unchecked i want certain things to happen. how can i accomplish this without the item checked event handler taking over every time i add an item to the listview?
Put your code in the
ItemCheck
event handler, rather thanItemChecked
. ItemCheck does not fire when an item is added.--EricDV Sig--------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters
-
ok say i have a list of items in the listview, when i either check or uncheck them i want certain things to happen. but if i add an item to the listview, it fires the event handler as if i checked or unchecked an existing item and i want to block it from doing that.
How about when you add an item to the list view use the "Tag" property to indicate that it's just been added and thus ignore it later in the code:
private void AddItemToList()
{
ListViewItem lvi = new ListViewItem("New Item");
lvi.Tag = "ItemJustAdded";
this.listView.Items.Add(lvi);
}private void listView_ItemChecked(object sender, ItemCheckedEventArgs e)
{
if (e.Item.Tag == "ItemJustAdded")
return;
// Do normal check stuff here.
}
Formula 1 - Short for "F1 Racing" - named after the standard "help" key in Windows, it's a sport where participants desperately search through software help files trying to find actual documentation. It's tedious and somewhat cruel, most matches ending in a draw as no participant is able to find anything helpful. - Shog9 Ed
-
How about when you add an item to the list view use the "Tag" property to indicate that it's just been added and thus ignore it later in the code:
private void AddItemToList()
{
ListViewItem lvi = new ListViewItem("New Item");
lvi.Tag = "ItemJustAdded";
this.listView.Items.Add(lvi);
}private void listView_ItemChecked(object sender, ItemCheckedEventArgs e)
{
if (e.Item.Tag == "ItemJustAdded")
return;
// Do normal check stuff here.
}
Formula 1 - Short for "F1 Racing" - named after the standard "help" key in Windows, it's a sport where participants desperately search through software help files trying to find actual documentation. It's tedious and somewhat cruel, most matches ending in a draw as no participant is able to find anything helpful. - Shog9 Ed
Ed.Poore wrote:
How about when you add an item to the list view use the "Tag" property to indicate that it's just been added and thus ignore it later in the code:
You'dthen need to clear the tag either in the handler, or in the add method otherwise checks will be permanantly nonfunctional in new items.
-- Rules of thumb should not be taken for the whole hand.
-
Ed.Poore wrote:
How about when you add an item to the list view use the "Tag" property to indicate that it's just been added and thus ignore it later in the code:
You'dthen need to clear the tag either in the handler, or in the add method otherwise checks will be permanantly nonfunctional in new items.
-- Rules of thumb should not be taken for the whole hand.
That was left as an exercise to the reader ;P
Formula 1 - Short for "F1 Racing" - named after the standard "help" key in Windows, it's a sport where participants desperately search through software help files trying to find actual documentation. It's tedious and somewhat cruel, most matches ending in a draw as no participant is able to find anything helpful. - Shog9 Ed