listBox数据传递给textBox的实现问题!
霜烟若梦 2012-09-26 04:28:19 private void textBox1_TextChanged(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source = 10.60.2.133; uid = sa; pwd =123; database = rkdb_tq";
con.Open();
SqlCommand cmd = new SqlCommand("select top 5 zjhm from dbo.qhry where substring(zjhm,1," + textBox1.Text.Length + ")='" + textBox1.Text + "'");
DataSet ds = new DataSet();
SqlDataAdapter adp = new SqlDataAdapter(cmd.CommandText, con);
adp.Fill(ds);
if (ds.Tables.Count > 0)
{
if (ds.Tables[0].Rows.Count > 0)
{
this.listBox1.Visible = true;
this.listBox1.Items.Clear();
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
this.listBox1.Items.Add(ds.Tables[0].Rows[i][0].ToString());
}
}
}
}
private void listBox1_SelectedValueChanged(object sender, EventArgs e)
{
if (this.listBox1.SelectedItems.Count > 0)
{
this.textBox1.Text = this.listBox1.SelectedItem.ToString();
}
if (this.listBox1.Items.Count > 0)
{
for (int i = 0; i < this.listBox1.Items.Count; i++)
{
if (listBox1.SelectedItems != null)
{
this.listBox1.Text = listBox1.SelectedItems[i].ToString();
}
}
this.listBox1.Visible = true;
this.Focus();
}
else
{
this.listBox1.Visible = false;
}
}
private void listBox1_MouseDoubleClick(object sender, MouseEventArgs e)
{
textBox1.Text = listBox1.SelectedItem.ToString();
this.listBox1.Visible = true;
}
}
以上是我写的listBox方法和doubleClick方法。我想实现:双击listBox中记录,textBox中显示这条记录。请各位帮忙看看为什么没有传递数据显示在textBox中?