在C#的列表框中显示文本框的一部分

时间:2016-07-19 08:12:37

标签: c#

我的c#表单应用程序中有一个文本框和一个列表框。我想要做的是用户将在文本框中输入查询,我想将该查询的部分显示在我的列表框中。

例如: enter image description here

在这里,我想在名为“查询选项”的列表框中显示“att1”和“att2”(即listBox1)。我怎么能这样做?

这是我到目前为止编写的代码:

  private void textBox1_TextChanged(object sender, EventArgs e)
    {

        string x = (sender as Control).Text;
        listBox1.BeginUpdate();
        try
        {
            XmlDocument xdata = new XmlDocument();
            xdata.Load("C:\\Ankush\\Visual Studio Project\\Query Info.xml");
            XmlNodeList qlist = xdata.SelectNodes("information/QueryInfo/Query");

            for (int i = 0; i < listBox1.Items.Count; i++)
            {
                if (listBox1.Items[i].ToString().ToLower().Contains(textBox1.Text.ToLower()))
                    listBox1.SetSelected(i, true);
                foreach (XmlNode node in qlist)
                {
                    listBox1.DataSource = xdata;
                    listBox1.Items.Add(node.InnerText);
                }
            }
            //listBox1.DataSource = xdata;
            string cmdstr = @"select * from information_schema.columns where table_name = '" + comboBox1.SelectedItem + "'";
            string conStr = @"Data Source=INPDDBA027\NGEP;Initial Catalog=Dev_Server;Integrated Security=True";
            DataTable dt = new DataTable();
            SqlDataAdapter sda = new SqlDataAdapter(cmdstr, conStr);
            sda.Fill(dt);
            listBox2.DataSource = dt;
            listBox2.DisplayMember = "Column_Name";
        }
        finally
        {
            listBox1.EndUpdate();
        }

    }

请帮助。

0 个答案:

没有答案