Get SQL data via listbox -


ok, trying click 1 item in listbox have, listbox gets data sql database depending on user types textbox.

now when click item in first listbox, need more info related item show in 2nd list box. when user enters name in textbox, first 10 in sql show up, have that, need click on 1 of items , 'task' of client in next listbox. task matters in database.

i pretty sure code correct, no errors nothing shows in list box.

here code:

private void listbox1_selectedvaluechanged(object sender, eventargs e) {    string item = listbox1.selecteditem.tostring();     if (listbox1.containsfocus)    {        if (item == "")        {         }        else        {            var con2 = conn.connstring();             using (sqlconnection myconnection2 = new sqlconnection(con2))            {                string ostring2 = "select clientmatters.matter, clientmatters.description clientmatters join clientcodes on clientmatters.client = clientcodes.client clientcodes.description = '@code1'";                  sqlcommand ocmd = new sqlcommand(ostring2, myconnection2);                ocmd.parameters.addwithvalue("@code1", item);                myconnection2.open();                 ocmd.connection.open();                list<string> codelist2 = new list<string>();                 using (sqldatareader oreader2 = ocmd.executereader())                {                   if (oreader2.hasrows)                   {                      string value = string.empty;                      while (oreader2.read())                      {                         codelist2.add(oreader2["matter"].tostring());                      }                    }                }                 this.listbox2.datasource = codelist2;            }        }     } } 

you need use bindinglist<> instead of list<>.

the list<> doesn't implement listchanged event, listbox doesn't notified when datasource changes.

in example this:

bindinglist<string> codelist2 = new bindinglist<string>(); 

for further information take @ bindinglist on msdn.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -