本文介绍了在文本框中输入文本时,在列表框中显示搜索结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个列表框,试图运行一些过滤查询,以便列表框中显示的内容是过滤查询的结果。下面是我的代码,它实际上带来了错误

Hi,
I have a list box that am trying to run some filter query so that what is displayed on the listbox is the result of the filter query. Below is my code that is actually bringing an error

        private DataView view;
        private void txtSearch_TextChanged(object sender, EventArgs e)
        {
            if(radioButton1.Checked)
            {
                string input = txtSearch.Text;
                string conn = "Connection String here";
                MySqlConnection myconn = new MySqlConnection(conn);
                string sql = "(Column1 LIKE '%" + sea + "%' OR Column2 LIKE '%" + sea + "%' OR Column3 LIKE '%" + sea + "%')";
//Column1, Column2 and Column3 represent some of my table columns
                MySqlDataAdapter da = new MySqlDataAdapter(sql, myconn);
                DataTable dt = new DataTable();
                da.Fill(dt);
                view = dt.DefaultView;
                listBox1.DataSource = view;
            
            }
}



我得到的错误是列表框上显示的内容是这个


The Error that am getting is that what is displayed on the listbox is this

System.Data.DataRowView



请帮助我确定我在哪里犯了错误。我将不胜感激任何想法。

谢谢


Please kindly help me identify where i did a mistake. I will appreciate any idea shared.
Thanks

推荐答案

this.listBox1.DataSource = dt;
this.listBox1.DisplayMember = "<required column name in the dt>";



应解决问题。



问候。


Should solve the issue.

Regards.


这篇关于在文本框中输入文本时,在列表框中显示搜索结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 23:04