一个Textbox控件 一个按钮 listbox已连接ACCess数据库 如何操作点击botton ,利用循环判断texebox.text文本与listbox里面的某个值相等,得到listbox中该值的SelectedIndex=k,触发listBox2_SelectedIndexChanged事件,使得listbox选中SelectedIndex=k的值???大侠帮忙啦
调试欢乐多
if(listBox1.Items.Contains(textBox1.Text))
{
listBox1.Text=textBox1.Text;
}
if(listBox1.Items.IndexOf(textBox1.Text)!=-1)
{
listBox1.SetSelected(listBox1.Items.IndexOf(textBox1.Text),true);
}
for(int i=0;i<listBox1.Items.Count;i++)
{
if(listBox1.Items[i].ToString().Equals(textBox1.Text))
{
listBox1.Text=textBox1.Text;
}
}
private void button2_Click(object sender, System.EventArgs e)
{
if(listBox1.Items.Contains(textBox1.Text))
{
listBox1.Text=textBox1.Text;
}
listBox1_SelectedIndexChanged(sender,e);
}//这个是双击listBox自动生成的事。
private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
this.textBox1.Text="is changed";
}
{
if(this.textBox1.Text!="" && listBox1.Items.Count>0)
{
for (int i = 0; i < listBox1.Items.Count;i++ )
{
if (textBox1.Text == listBox1.Items[i].ToString())
{
this.listBox1.SelectedIndex = i;
break;
}
}
}
}