When I try to use this code on my ListBox, only the select index 0 executes.

#region SelectedIndex0
            if (listBox2.SelectedIndex == 0)
            {
                SelectedIndex0();
            }
            else { return; }
            #endregion
            #region SelectedIndex1
            if (listBox2.SelectedIndex == 1)
            {
                SelectedIndex1();
            }
            else { return; }
            #endregion

Hi Game,

It happed because you have put "else return" statement after listBox2.SelectedIndex == 0. It means code can't rich second condition.

Try using another structure:

if (listBox2.SelectedIndex == 0)
            {
                SelectedIndex0();
            }           
            else if (listBox2.SelectedIndex == 1)
            {
                SelectedIndex1();
            }
            else { return; }

Cheers

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.