郑德才博客 记录学习,记录工作,学习知识分享!

ListBox 控件中的项

private void Form1_Load(object sender, System.EventArgs e)
{
listBox1.Items.Add("Angelina");
listBox1.Items.Add("Isabella");
listBox1.Items.Add("Sarah");
}

private void button1_Click(object sender, System.EventArgs e)
{
// Set the search string:
string myString = "Isabella";
// Search starting from index -1:
int index = listBox1.FindString(myString, -1);
if (index != -1)
{
// Select the found item:
listBox1.SetSelected(index,true);
// Send a success message:
MessageBox.Show("Found the item \"" + myString +
"\" at index: " + index);
}
else
MessageBox.Show("Item not found.");
}
2012年3月27日 | 发布:郑德才博客 | 分类:学习之路 | 评论:0

发表留言: