Can’t seem to be able to set ListViewItem.imageIndex (C#)

Discussion in 'Programming & Software Development' started by Vampire, May 10, 2010.

  1. Vampire

    Vampire Member

    Joined:
    Dec 3, 2004
    Messages:
    747
    Location:
    Hawkesbury
    I have been scratching my head with this error for at least an hour, what the heck is wrong here?

    In a loop:

    Code:
    if (selectedItems[x].ImageIndex == 3)
                            {
                                List<ListViewItem> dupes = CP.listCache.FindAll(delegate(ListViewItem item) { return item.Text == selectedItems[x].Text; });
    
                                if (dupes != null && dupes.Count == 1)
                                    dupes[0].ImageIndex = 0;
                            }
    I can access the imageIndex, but not set it. ArgumentOutOfRange exception occurs.

    Any tips appreciated!
     
  2. azzachaz

    azzachaz Member

    Joined:
    Nov 5, 2003
    Messages:
    1,562
    Location:
    Canberra
    Can you post the Get/Set methods for ImageIndex?

    Is the set method doing some processing of the value rather than just passing the value through to a property?
     
  3. DePhantom

    DePhantom Member

    Joined:
    May 14, 2003
    Messages:
    104
    Location:
    Brisbane
    Check to see if your dupes list has an associated ImageList.
     
  4. Foliage

    Foliage Member

    Joined:
    Jan 22, 2002
    Messages:
    32,069
    Location:
    Sleepwithyourdadelaide
    What is imageIndex used for? Perhaps it cannot be set to 0 and has to start at 1?

    Best way is to post the code for ListViewItem and imageIndex.
     
  5. jezza323

    jezza323 Member

    Joined:
    Apr 7, 2005
    Messages:
    1,374
    Location:
    Brisbane
    you must have the imagelist set first, with at least 1 item in it, or index 0 will be out of range

    EDIT: what DePhantom said
     

Share This Page

Advertisement: