日期:2014-05-17  浏览次数:20696 次

C# listbox 读取数据
C#中有两个listbox,想把左边listbox里的内容移到右边……左边listbox读取数据内容的代码如下:

SqlConnection conn = new SqlConnection("server =.;database = MySchool; uid = sa;");
conn.Open();
SqlCommand cmd = new SqlCommand("select Name from Student", conn);
SqlDataReader dr = cmd.ExecuteReader();
this.listBox1.Items.Clear();
while (dr.Read())
{
  this.listBox1.Items.Add(dr[0].ToString());
}
dr.Close();
conn.Close();

可是为什么运行的时候内容要点一下空白处才能显示出来,而且根本不能选中某一项,点了就闪开,要怎么解决啊?!!!!
C# ListBox

------解决方案--------------------
你写在什么事件里了?
------解决方案--------------------
引用:
引用:C#中有两个listbox,想把左边listbox里的内容移到右边……左边listbox读取数据内容的代码如下:

SqlConnection conn = new SqlConnection("server =.;database = MySchool; uid = sa;");
conn.Open();
SqlComma……

那当然,你点下空白才会触发SelectChanged。