0

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!");
            }
4

2 に答える 2

1

これを試して

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]);
}

ポップアップ メッセージ ボックスに表示される内容を教えてください。

于 2009-10-22T03:06:30.227 に答える
0
RemovePackages_Listbox.SelectedIndex

ListBox で選択された項目の 0 から始まるインデックスを返します。

だからあなたは尋ねています:

リストボックスに表示されるテキストが、ChoiceTitle リストの SELECTEDINDEX の位置にある文字列と同じ場合-

これを行う。

トリプルチェックしてください。

于 2009-10-22T03:06:21.627 に答える