0
リストボックスで文字列を検索しようとしています。見つかった場合はメッセージボックスを表示し、そうでない場合は別のメッセージボックスを表示します。しかし、私は偽の部分でエラーを取得しています。助けてください。リストボックスから読み取るときにエラーが発生する
{
string myString = metroTextBox1.Text;//username
// Search starting from index -1:
int index = listBox1.FindString(myString, -1);//username
if (index != -1)
{
listBox1.SetSelected(index, true);//username
MessageBox.Show("ok");
}
else
{
listBox1.SetSelected(index, false);//username
MessageBox.Show("error");
}
}
どのようなエラー....? – Gusman
なぜ他の部分で-1に設定されている場合にインデックスにアクセスしようとしていますか? 'listBox1.SetSelected(index、false);' –