c# listbox选中项在textbox显示并可修改

2024-11-18 18:26:35
推荐回答(3个)
回答1:

给LISTBOX添加ONCLICK事件,在这个事件发生时,将这个LISTBOX的SELECTEDITEM的TEXT赋值给TEXTBOX的text,然后,点击这个修改按钮时,触发ONCLICK事件,将LISTBOX的值修改了,然后绑定
我来写代码,你等等,如果上面的思路够用了,那你自己写







protected void lbData_SelectedIndexChanged(object sender, EventArgs e)
{
this.txtChange.Text= this.lbData.SelectedItem.Text;

}

protected void btnSubmit_Click(object sender, EventArgs e)
{
this.lbData.SelectedItem.Text = txtChange.Text;
}

回答2:

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if(this.listBox1.SelectedIndex!=-1) //必要
this.textBox1.Text = this.listBox1.SelectedItem.ToString();
}

private void button4_Click(object sender, EventArgs e)
{
this.listBox1.Items[this.listBox1.SelectedIndex] = this.textBox1.Text;
}

回答3:

没有那么麻烦吧?
int i;
private void listBox1_Click(object sender, EventArgs e)
{
i = this.listBox1.SelectedIndex;
this.textBox1.Text = this.listBox1.SelectedItem.ToString();
}
private void button1_Click(object sender, EventArgs e)
{
this.listBox1.Items[i] = this.textBox1.Text;
}