CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Byte to Item

  1. #1
    Join Date
    Sep 2002
    Posts
    223

    Byte to Item

    foreach (byte key in keys)
    {

    listView1.Items.Remove(????);
    }

    Remove require an Item, how do I go from a key byte to an Item ?

  2. #2
    Join Date
    Dec 2003
    Location
    http://map.search.ch/zuerich.en.html
    Posts
    1,074
    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]);

  3. #3
    Join Date
    Sep 2002
    Posts
    223
    Thanks !

    Puttet this as a member to my IDictionary Interface.

    Object lookup(Object key);

    But how do I make lookup understandble for the compiler !
    Last edited by Jedhi; February 18th, 2004 at 12:59 PM.

  4. #4
    Join Date
    Dec 2003
    Location
    http://map.search.ch/zuerich.en.html
    Posts
    1,074
    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]); 
    }

  5. #5
    Join Date
    Sep 2002
    Posts
    223
    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 ???

  6. #6
    Join Date
    Dec 2003
    Location
    http://map.search.ch/zuerich.en.html
    Posts
    1,074
    It's probably complaining about

    Code:
    listView1.Items.Remove(lookup[key]);
    (maybe) it should be:

    Code:
    listView1.Items.Remove((ListViewItem)lookup[key]);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured