Click to See Complete Forum and Search --> : Byte to Item
Jedhi
February 18th, 2004, 09:56 AM
foreach (byte key in keys)
{
listView1.Items.Remove(????);
}
Remove require an Item, how do I go from a key byte to an Item ?
Norfy
February 18th, 2004, 11:06 AM
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]);
Jedhi
February 18th, 2004, 11:32 AM
Thanks !
Puttet this as a member to my IDictionary Interface.
Object lookup(Object key);
But how do I make lookup understandble for the compiler !
Norfy
February 18th, 2004, 01:49 PM
Not sure what you mean!
What I mean (based on your previous posts):
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]);
}
Jedhi
February 18th, 2004, 02:26 PM
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 ???
Norfy
February 23rd, 2004, 01:47 AM
It's probably complaining about
listView1.Items.Remove(lookup[key]);
(maybe) it should be:
listView1.Items.Remove((ListViewItem)lookup[key]);
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.