Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
ListBox problems
Message
From
02/03/2005 15:36:11
 
General information
Forum:
ASP.NET
Category:
Forms
Miscellaneous
Thread ID:
00992047
Message ID:
00992140
Views:
14
Chad,

Well, whaddaya know? It actually works! Very strange ... I don't know why setting the .SelectedIndex to 0 prior to setting the DataSource to null would make the difference, but it does. The weird thing is that as soon as you set the DataSource to null, the .SelectedIndex goes to -1 (which I would expect) ... so how the heck does setting it to 0 before it goes to -1 make it work?

Very, very peculiar!!

~~Bonnie


>Einar,
>
>I would actually expect an error by setting the Selected index after setting the datasource to null. I just tested this and it works for me:
>
>
>int index = this.listBox1.SelectedIndex;
>this.listBox1.SelectedIndex = 0;
>this.listBox1.DataSource = null;
>this.oCol.RemoveAt(index);
>this.listBox1.DataSource = this.oCol;
>this.listBox1.Refresh();
>
>
>I doubt the Refresh() is necessary. And you could also build in some logic to reposition the selected index close to where it was.
>
>HTH,
>Chad
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform