none
About ListView RRS feed

  • Question

  • Hello,

    I was very rarely using ListView, seems it is time to ask question:

    I am building an element that way

    ListViewItem BuildItem(string name, string fullName, bool state)
            {
                ListViewItem i = new ListViewItem(name, 0);  
                i.StateImageIndex = state ? 0 : 1;            
                i.ImageIndex = state ? 0 : 1;            
                i.SubItems.Add(fullName);            
                return i;        
            }
    Then just add  
    userList.Items.Add(BuildItem(ID, fullName, true));

    So, there is an image in the item (imageindex in imageList). Now I want to find an Item in that ListViewBox with some Name (ID) and change the image index to false value;

    How should I perform the search thriugh that Items list? I can't get the ContainsKey as I do not use Key. How to add a Key to that kind of ListViewItem?

    Tuesday, July 30, 2019 11:56 AM

Answers

  • And you need to add one additional line to set the name of your ListViewItem:

    ListViewItem BuildItem(string name, string fullName, bool state)         {             ListViewItem i = new ListViewItem(name, 0); 

    i.Name = name;           i.StateImageIndex = state ? 0 : 1;            i.ImageIndex = state ? 0 : 1;            i.SubItems.Add(fullName);            return i;        }

    • Marked as answer by RobbKirk Tuesday, July 30, 2019 12:37 PM
    Tuesday, July 30, 2019 12:23 PM

All replies