c# - SelectedIndex causing a crash although it is being set to zero -


the code in listbox in silverlight application think issue not specific here code:

    mylistbox processlistbox = (sender mylistbox);     if (processlistbox != null)     {         if (processlistbox.selecteditem == null)             processlistbox.selectedindex = 0;     } 

so crashing on

processlistbox.selectedindex = 0; 

with indexoutofrange exception , weird thing when hover on selectedindex showing -1 let's crazy reason value -1 still setting 0 why still crashes?

maybe it's simple? if listbox contains no items, setting

processlistbox.selectedindex = 0; 

will throw indexoutofrange exception because there nothing select...


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -