By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,331 Members | 1,278 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,331 IT Pros & Developers. It's quick & easy.

Listbox problems

P: n/a
Hi,
Can anyone explain to me why SelectedIndex is automatically changed to 0
when I set it to -1?

This happens when I set SelectedIndex = -1 from the click-eventhandler of a
button. My ListBox is bound to an ArrayList.

Thanks! /K
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi Karin,

Check your handler for SelectedIndexChange , the problem may be there.

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Karin" <kl@inxl.se> wrote in message
news:u3**************@tk2msftngp13.phx.gbl...
Hi,
Can anyone explain to me why SelectedIndex is automatically changed to 0
when I set it to -1?

This happens when I set SelectedIndex = -1 from the click-eventhandler of a button. My ListBox is bound to an ArrayList.

Thanks! /K

Nov 13 '05 #2

P: n/a
Hi,
I thought so first too so I made a very simple form with just one listbox
and a button to try it out without the eventhandler for SelectedIndexChanged
but the problem was still there.
Strange thing is that it works as expected when SelectedIndex = 0 before the
button is clicked.
I have found a way to avoid the problem which I don't really like but it
works...

private bool blnNew = false;
private void lb_SelectedIndexChanged(object sender, System.EventArgs e)
{
if (lb.SelectedIndex != -1 )
{
if (blnNew)
lb.ClearSelected();
}
private void button1_Click(object sender, System.EventArgs e)
{
blnNew=true;
lb.ClearSelected();
blnNew=false;
}

/K

"Ignacio Machin" <ignacio.machin AT dot.state.fl.us> wrote in message
news:#G**************@TK2MSFTNGP10.phx.gbl...
Hi Karin,

Check your handler for SelectedIndexChange , the problem may be there.

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Karin" <kl@inxl.se> wrote in message
news:u3**************@tk2msftngp13.phx.gbl...
Hi,
Can anyone explain to me why SelectedIndex is automatically changed to 0
when I set it to -1?

This happens when I set SelectedIndex = -1 from the click-eventhandler
of a
button. My ListBox is bound to an ArrayList.

Thanks! /K


Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.