C# WinForm ListBox控件Selection属性为MultiExtended                 //数据绑定代码
                DT = ODA.SelectCommand().Tables[0];
                listBox1.DataSource = DT;
                listBox1.DisplayMember = "xm"; //显示值得字段名称
                listBox1.ValueMember = "id"; //绑定值的字段名称比如现在想把id=2,3,5的值默认被选中该怎么做?

解决方案 »

  1.   

    好像没什么好的办法,只能循环检测了。
    WPF应该可以把属性捆定到item的property上去。
                List<Person> people = new List<Person>();
                people.Add(new Person { Age = 25, FirstName = "Alex", LastName = "Johnson" });
                people.Add(new Person { Age = 23, FirstName = "Jack", LastName = "Jones" });
                people.Add(new Person { Age = 35, FirstName = "Mike", LastName = "Williams" });
                people.Add(new Person { Age = 25, FirstName = "Gill", LastName = "JAckson" });
                this.listBox1.DataSource = people;
                this.listBox1.DisplayMember = "FirstName";
                this.listBox1.ValueMember = "Age";            for (int i = 0; i < listBox1.Items.Count; ++i)
                {
                    if (((Person)listBox1.Items[i]).Age == 25)
                        listBox1.SetSelected(i, true);
                }
      

  2.   

    添加上checkbox可以实现,和楼上同解