foreach (byte key in keys)
{
listView1.Items.Remove(????);
}
Remove require an Item, how do I go from a key byte to an Item ?
Printable View
foreach (byte key in keys)
{
listView1.Items.Remove(????);
}
Remove require an Item, how do I go from a key byte to an Item ?
Hi Jedhi,
if I remember some of your earlier posts correctly, you are storing 'key' as a subitem in a ListViewItem.
In which case it is not a simple case of converting 'key' to ListViewItem.
Maybe the easiest way is to create a Hashtable of 'key' against its containing ListViewItem and then you can use:
listView1.Items.Remove(lookup [key]);
Thanks !
Puttet this as a member to my IDictionary Interface.
Object lookup(Object key);
But how do I make lookup understandble for the compiler !
Not sure what you mean!
What I mean (based on your previous posts):
Code:Hashtable lookup = new Hashtable();
ListViewItem item = new ListViewItem(new string[] {key, value});
lookup.Add(key, item);
listView1.Items.Add(item);
etc.
foreach (byte key in keys)
{
listView1.Items.Remove(lookup[key]);
}
I thought that lookup was some fancy word. But I can see now it is the name of the hashtable... LOL.
I've already done as you described, but I get an error CS1502 + CS1503 telling that Argument '1': cannot convert from 'object' to 'System.Windows.Forms.ListViewItem'
The Remove in IDictionary looks like this:
void Remove(Object key);
// should it be void Remove(byte key) instead ???
It's probably complaining about
(maybe) it should be:Code:listView1.Items.Remove(lookup[key]);
Code:listView1.Items.Remove((ListViewItem)lookup[key]);