B
Beringer
Hello,
I have a listview and have set the MultiSelect property to false.
I assumed that if I monitored the OnSelectedIndexChanged event that I could
obtain the currently selected item from the SelecteItems collection by
referencing the 0 index.
When I do this however, I get a runtime exception telling me I have exceded
the size of the collection. The debugger shows the collection to be empty.
So my question is, "Is the OnSelectedIndexChanged event created before or
after the SelectedItems collection is updated?"
I have found that if I use the ItemActivate event my code works but I don't
really want to use ItemActivate.
I have provided a snipet of code below.
private void OnSelectedIndexChange_lvSearchResults(object sender,
System.EventArgs e) {
ListView.SelectedListViewItemCollection items =
(ListView.SelectedListViewItemCollection)lv.SelectedItems;
ListViewItem selectedItem = (ListViewItem)items[0];
etc.
}
The exception is thrown on the second line.
Thank you in advance,
Eric
I have a listview and have set the MultiSelect property to false.
I assumed that if I monitored the OnSelectedIndexChanged event that I could
obtain the currently selected item from the SelecteItems collection by
referencing the 0 index.
When I do this however, I get a runtime exception telling me I have exceded
the size of the collection. The debugger shows the collection to be empty.
So my question is, "Is the OnSelectedIndexChanged event created before or
after the SelectedItems collection is updated?"
I have found that if I use the ItemActivate event my code works but I don't
really want to use ItemActivate.
I have provided a snipet of code below.
private void OnSelectedIndexChange_lvSearchResults(object sender,
System.EventArgs e) {
ListView.SelectedListViewItemCollection items =
(ListView.SelectedListViewItemCollection)lv.SelectedItems;
ListViewItem selectedItem = (ListViewItem)items[0];
etc.
}
The exception is thrown on the second line.
Thank you in advance,
Eric