windows 窗体中 listbox的遍历,判断是否选中,我刚学,对于这些还不懂,请哪位告诉我,谢谢

解决方案 »

  1.   


    //ListBox在groupBox1中
    foreach (Control ctl in this.groupBox1.Controls)
                {
                   // MessageBox.Show(ctl.GetType().Equals("ListBox");
                    if (((ListBox)ctl).Focus())//是否获取焦点
                    {
                        MessageBox.Show(((ListBox)ctl).SelectedItem.ToString());//显示选中的值
                    }
                }
      

  2.   

    忽略这句
    // MessageBox.Show(ctl.GetType().Equals("ListBox");
      

  3.   

    加上Check属性,遍历Checked属性是否为true
      

  4.   

     for (int i = 0; i < listBox1.Items.Count; i++)
                {
                    string message = listBox1.Items[i].ToString();
                    listBox2.Items.Add(message);
                }   
    那这样写有错吗,为什么没有值啊
      

  5.   

    上MSDN看看,参考