c# ListBox选中一项时,在TextBox中显示选中项文本(要按下回车键)
private void listBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (this.listBox1.SelectedItem != null)
{
textBox1.Text = this.listBox1.SelectedItem.ToString();
}
}
如果 A001 电脑部, 但只需要显示 A001 时
private void listBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (this.listBox1.SelectedItem != null)
{
textBox1.Text = this.listBox1.SelectedItem.ToString().Substring(0,4).Trim();
}
}