c# - Windows forms Listbox won't show the right text for each item -


i done project. tested , worked , showed right values.

today won't show right text in listbox.

here code:

private void filmbtnloadfilms_click(object sender, eventargs e) {     filmserviceclient filmclient = new filmserviceclient("nettcpbinding_ifilmservice");     showserviceclient showclient = new showserviceclient("nettcpbinding_ishowservice");      filmrecord[] list = null;     try     {         //retrieve films         if (list == null)         {             list = filmclient.retrieveallfilms();         }         if (filmlist.items.count > 0)         {             filmlist.items.clear();         }         foreach (var film in list)         {             filmlist.items.add(film);         }          this.filmlist.datasource = list;         this.filmlist.displaymember = "title";         this.filmlist.valuemember = "id";     }     catch     {         loglabel.text = "film kunne ikke indlæses";     }     showclient.close();     filmclient.close(); } 

hope can finding answer. upfront thanks.

new update. if move calls come datasource, datamember , value member filmlist.valuemember gives argument exception unhandled.

first thing, not fill data both ways listbox. can either use items.add or datasource. let's say, use latter. in way need not have worry items.clear() also. so, in order display title, need override tostring() of class, filmrecord.

public override string tostring() { return this.title; } 

this done because default, listbox calling tostring under hood. calling method on class object reveals name of class , namespace unless overridden provide custom implementation.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -