Click here to Skip to main content
16,004,778 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
C#
        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
C#
System.Data.DataRowView

Please kindly help me identify where i did a mistake. I will appreciate any idea shared.
Thanks
Posted
Updated 14-Dec-12 2:42am
v2
Comments
thursunamy 14-Dec-12 9:20am    
Try to set listBox1.DisplayMember = "Column Name"
Xonel 14-Dec-12 12:05pm    
Thank you soo much thursunamy! That worked pretty well!

1 solution

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

Should solve the issue.

Regards.
 
Share this answer
 
Comments
Xonel 14-Dec-12 12:06pm    
Thank you soo Much wmdroshan! That worked out! Thanks for the reminder

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900