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);' –