1、listbox怎样添加value值?
2、listbox怎样取出任意一行的text和value 值?
期待您的解答!!

解决方案 »

  1.   

    1.this.listBox1.Items.Insert(.......);
    2.this.listBox1.SelectedItem.ToString();
      

  2.   

    1>this.ListBox1.Items.Add(new ListItem("Oxygen", "O")); 
    2>
    ListBox1.SelectedItem.Text;
    ListBox1.SelectedItem.Value;   //单选可以用如果是多选的话用foreach循环来获得选定选的值!
      

  3.   

    ListView1.Items.Add(new ListViewItem(str));
      

  4.   

    大大第二个问题是取任意行的value和text而不是选定行,我该怎么办?
      

  5.   

    this.listBox1.Items[任意行索引].ToString();
      

  6.   

    to   xczgb(民工乐园) :
    this.listBox1.Items[任意行索引].ToString();  ???
    没有这样的方法!!
      

  7.   

    应该是
    this.listBox1.Items[任意行索引].Text.ToString();
    this.listBox1.Items[任意行索引].Value.ToString();
      

  8.   

    几位大大恐怕都没有经过实际操作吧?Items[index]后没有text或者value属性的!!
      

  9.   

    winform是没有text或value的值的。。this.listBox1.Items[0].ToString(); 我测试过。
      

  10.   

    to  xczgb(民工乐园) :
    当然是winform,web哪会有LIstbox
      

  11.   

    那我该如何取到value和text呢?
      

  12.   

    to  oldbee01(老蜜蜂)  :
         to  xczgb(民工乐园) :
         当然是winform,web哪会有LIstboxweb 当然有listbox,拜托,看来大家都是半调子,哈哈
      

  13.   

    而且我的方法在web下是可行的,只是你没说清是web还是winform吧了
      

  14.   

    To: fystar1978(风夜) 
    在winform里有“this.listBox1.Items[任意行索引].Text.ToString()”这样的?????
      

  15.   

    To:xczgb(民工乐园)    To: fystar1978(风夜) 
       在winform里有“this.listBox1.Items[任意行索引].Text.ToString()”这样的?????我说了“而且我的方法在web下是可行的,只是你没说清是web还是winform吧了

    xczgb(民工乐园)你的眼睛怎么看的哦
      

  16.   

    争论这些没什么意义,我对WINFORM不熟悉,当我什么也没说好了,云
      

  17.   

    private void Form3_Load(object sender, System.EventArgs e)
    {
    for(int i=0;i<10;i++)
    {
    Item obj =new Item();
    obj.strText ="显示文本"+i.ToString();
    obj.strValue =i.ToString();
    this.listBox1.Items.Add(obj);
    }
    } private void button3_Click(object sender, System.EventArgs e)
    {
    Item obj =this.listBox1.SelectedItem as Item;
    if(obj!=null)
    {
    MessageBox.Show("Text:"+obj.strText+" 值:"+obj.strValue);
    }
    }
    }
    public class Item
    {
    public string strText;
    public string strValue;
    public override string ToString()
    {
    return this.strText;
    } }
      

  18.   

    没明白在争论什么。。答案都给了那么多了。。listbox。。item只有显示的text字段,没有value吧。。