Question

I'm trying to get it to verify that it has the same item in the List as the one that's currently selected in the listbox

Why does this code not work, It should work unconditionally because the text generated from the listbox is taken from the List choicetitle

if (RemovePackages_Listbox.Text == choicetitle[RemovePackages_Listbox.SelectedIndex])
            {
                MessageBox.Show("The above code worked!");
            }
Was it helpful?

Solution

Try this

if (RemovePackages_Listbox.SelectedItem.ToString() == choicetitle[RemovePackages_Listbox.SelectedIndex])
            {
                MessageBox.Show("The above code worked!");
            }

else
{
    MessageBox.Show("RemovePackages_Listbox.SelectedItem.ToString() is "+RemovePackages_Listbox.SelectedItem.ToString()+" and choicetitle[RemovePackages_Listbox.SelectedIndex] is "+choicetitle[RemovePackages_Listbox.SelectedIndex]);
}

And tell us what you see in the popup messagebox?

OTHER TIPS

RemovePackages_Listbox.SelectedIndex

will return a zero-based index of the selected item in the ListBox.

So you're asking:

If the text displayed in my Listbox is the same as the string in my ChoiceTitle List at position SELECTEDINDEX -

Do this.

Triple check that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top