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