Foreach ListItems在列表框帮助中! [英] Foreach ListItems in Listbox HELP!

查看:146
本文介绍了Foreach ListItems在列表框帮助中!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  foreach (ListItem li  in  ListBox.Items中)
              {
                  如果(li.Selected == )
                  {
                      // 您要分配给TextBox的内容
                      名称= li.Text = " ;

                      ProductNumber = li.Text = " ;


                      ListPrice = li.Text = " ;
                      颜色= li.Text = " ;
                      MoreInfo = li.Text = " ;

                      名称= li.Text = li.Text +



                  } 



我已经这样写了,但是我不确定在代码中写什么,
我想在写的列表框中的项目中选择

 如果(ListBox.SelectedItem!= )
                    名称= ListBox.SelectedItem.Text; 



然后当我在列表框中选择一个项目时我首先要编写的代码在文本框中显示所有信息,所以我的问题是我真的不知道在我的foreach循环中要写什么! >解决方案

私有 对象发​​件人,EventArgs e)
       {
           textBox1.Text = listBox1.SelectedItem.ToString();
       } 


foreach (ListItem li in ListBox.Items)
              {
                  if (li.Selected == true)
                  {
                      // what ever you want to assign to TextBox
                      Name = li.Text = "";

                      ProductNumber = li.Text = "";


                      ListPrice = li.Text = "";
                      Color = li.Text = "";
                      MoreInfo = li.Text = "";

                      Name=li.Text=li.Text+



                  }



i have written like this but i am not sure what to write in the code,
i want to when i select in item in the listbox i have written

if (ListBox.SelectedItem != null)
                    Name = ListBox.SelectedItem.Text;



then the code that i writted first i want to when u select an item in the listbox show all in the info in the textboxes , so my problem is that i dont really know what to write in my foreach loop!

解决方案

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
       {
           textBox1.Text= listBox1.SelectedItem.ToString();
       }


这篇关于Foreach ListItems在列表框帮助中!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆