Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unable to put a listbox index to -1

Status
Not open for further replies.

vilrbn

Programmer
Oct 29, 2002
105
0
0
FR
Hello,

I have three listboxes: ListA, listB, listC.
ListC is updated according to listB choice.

If I click on ListA, my SelectedIndex takes a value.

If I click on ListB just after, I want to set listA index to -1:

listA.SelectedIndex = -1

I can check in the watch window that it it set to -1 but... in reality my ListA' SelectedIndex is set to 0 (first item in the list).
So if I action my search clicking on a button, I'm not able to know if ListA or ListB has been selected as the two indexes are different from -1.

Does anybody already have the same problem ? It drives me crazy, help !

 
Just use listA.ClearSelection. This should do what you want it to do! (I don't know why you can't manually do it. . . one of the great mysteries of the universe :-D)

HTH Kevin B.
.Net Programmer [thumbsup]
 
In fact I also have tried ClearSelection method. Like SelectedIndex = -1, It's working, but... my indexes having -1 turned back to 0 when I click on one of my button.
To solve the problem, for each list, I'm inserting a blank record at page loading:

listA.Items.Insert(0, New ListItem(""))
...

and I'm testing that SelectedIndex is greater than 0 !

That's bypassing this strange behaviour.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top