Click to See Complete Forum and Search --> : Adding item to listbox makes all UNselectable.


ThermoSight
November 11th, 2005, 07:25 PM
I am having a difficult problem working with a ListBox. Perhaps someone can help.

When the form's constructor is called, it in turn calls on 'PopulateSitesList()' to read in site records and place the name of each in the ListBox. This works well - all records are present and all are selectable. However, manually adding a single additional sitename to the list causes ALL names to be unselectable.

Since I initially submitted this question, I have had to revise my thinking....

The new name *does* appear in the site list, and in the right order (so PopulateSitesList() worked satisfactorily), and the debugger shows that the collection is (or at least, appears to me to be) good.

However, after updating the list box with the additional item, when I click on an item to select it, get_SelectedIndex() returns the correct index value BUT in the very next statement, get_SelectedItem() traps out with an "index out of bounds" exception.

The index returned by get_SelectedIndex() is always correct but get_SelectedItem() always traps out with the "index was outside the bounds of the array" exception. (as mentioned earlier, this does not happen until an item is added).

Bottom line is that the updated listbox LOOKS good, but one cannot select anything: get_SelectedIndex() and get_SelectedItem() do not agree.

interesting problem, huh?


Thanks,

bill

ThermoSight
November 11th, 2005, 10:26 PM
Well, as it turns out, I **MAY** have found the problem......

30 seconds after posting the note above, I found and removed the statement "SiteList->ClearSelect()".

Initially I thought this statement was necessary to clear the selected item when the constructor has populated the ListBox.

For reasons I do not understand, item 0 is selected when the form first appears, even though no user intervention has taken place - the ClearSelect() statement was a lame attempt to prevent that selection. (no mouse clicks have occurred; how could any item be selected?)

Removing that statement has resolved the problem although I do not understand why. Clearly, I HAVE selected something subsequent to that statement, and method get_SelectedIndex() understood that a selection had been made, but apparently get_SelectedItem() didn't get the word.

In any event, after slightly more than 7 hours, it now appears to be working.

(I'm sorry about all the ugly things I said about you, Microsoft ... especially for referring to your ancestry in that ugly tone).

Best wishes to all.

bill