Listbox에서 항목의 텍스트 확인 C# 목록에서 동일합니다.
-
05-07-2019 - |
문제
목록에 현재 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.
제휴하지 않습니다 StackOverflow