문제

목록에 현재 Listbox에서 선택된 항목과 동일한 항목이 있는지 확인하려고합니다.

이 코드가 작동하지 않는 이유는 무엇입니까? Listbox에서 생성 된 텍스트가 List Choicetitle에서 가져 오기 때문에 무조건 작동해야합니다.

if (RemovePackages_Listbox.Text == choicetitle[RemovePackages_Listbox.SelectedIndex])
            {
                MessageBox.Show("The above code worked!");
            }
도움이 되었습니까?

해결책

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?

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top