You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何选中listBox1中的项并同步替换textBox1的内容?

实现选中ListBox1项后自动替换TextBox1内容

要实现选中listBox1里的选项后自动替换textBox1的内容,可通过监听ListBox的SelectedIndexChanged事件,在事件处理方法中编写如下逻辑:

if (listBox1.SelectedIndex >= 0)
{
   string strok = listBox1.SelectedItem.ToString();
   string name = strok.Split(' ')[0];
   var selgrah = name.ToLower();
   textBox1.Text = selgrah;
}

代码说明:

  • 先判断SelectedIndex是否≥0,确保存在被选中的项
  • 获取选中项的字符串内容,按空格分割后提取第一部分
  • 将提取的内容转为小写,赋值给textBox1.Text完成替换

内容的提问来源于stack exchange,提问作者user25391876

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 19:42:02