Skip to content

Retrievig subitem from ListView works, but only once!

Stephen Fletcher

Asked Jun 25, 2009, 7:05 AM EDT1 answer
Share
LinkedInX
in my lvConcepts_SelectedIndexChanged(..)
I have ...
   MessageBox.Show(lvConcepts.SelectedItems[0].SubItems[0].Text);
 
It works the first time I click on the ListView.  If I click again I get
"An unhandled exception of type 'System.ArgumentOutOfRangeException'
...   InvalidArgument=Value of '0' is not valid for 'index'."
 
What is going on!?
Thanks for any help.

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Hurrah! sorted.
    There is obviously some sort of deselect happening before the new selection.
    I wrapped a count check around my MessageBox line and it worked...
    if(lvConcepts.SelectedItems.Count > 0)
            MessageBox(...)
     
     
    and it worked.
    0