Setselected for listbox works with debug but not with Release mode

  • Thread starter Thread starter rnes1961
  • Start date Start date
R

rnes1961

I am using SetSelected to set a selected value on a listbox.

....
Console.Write("Ans 1: " & IntAns
lbAns1.SetSelected(IntAns, True)
Console.WriteLine(" Selected: " & lbAns1.SelectedIndex)
....

Where IntAns is an integer.

The thing is, it works just fine if I am in debug mode with a
breakpoint set anywhere. But if I take the breakpoint off, the index
does not get set.

Below is the results WITH a breakpoint set.

....
Ans 1: 3 Selected: 3
....

With NO breakpoint set

....
Ans 1: 3 Selected: 0
....

As you can see by the console.write commands the index gets set when a
breakpoint is set but not when the breakpoint is not set.

HELLPPP!!! I am at the end of my rope, with a target date looming.
 
I am using SetSelected to set a selected value on a listbox.

The thing is, it works just fine if I am in debug mode with a
breakpoint set anywhere. But if I take the breakpoint off, the index
does not get set.

Breakpoints and/or Release builds should not change the way a ListBox
behaves. So there is something else going on in your application.



Could you share a bit more information about your application? You mention
using Console.WriteLine calls. Are you still writing a Windows Forms
application? Is the listbox working okay interactively?



Note that if you manipulate components with a user interface (like ListBox)
in a piece of code, the UI might not be immediately updated unless you
implicitly or explicitly call Application.DoEvents. This might have bitten
you this time. Is the code you showed part of a larger code block? How and
when is the code executed?



Again, more information would be needed to solve the issue you are having.


--
Regards,

Mr. Jani Järvinen
C# MVP
Helsinki, Finland
(e-mail address removed)
http://www.saunalahti.fi/janij/
 
I found the problem. I was trying to update the listbox in the
constructor. I moved it to the page_load and now its working.

Thanks.
 
Back
Top