c# - Combobox displaymember issue, driving me crazy -


sorry bother, have problem c# winforms, since i've been searching same problem, found solutions they're not working me. ok, have bindinglist objects

bindinglist<objects.usuario> usuarios = new bindinglist<objects.usuario>(); 

the objects have public strings , int variables, 1 string , 1 int variables need.

public string datanombrecompleto; public int dataidusuario; 

so, once list "usuarios" has objects, this

            cbadministrativos.displaymember = "datanombre";             cbadministrativos.valuemember = "dataidusuario";             cbadministrativos.datasource = usuarios; 

and thing is, it's not working, combobox (cbadministrativos) still displays object.

when go through debugger, after breakpoint, combobox sets display member, valuemember , datasource, code goes, but, in next instruction (the end of method), realized displaymember, magically, turns "" instead string "datanombre".

any idea?

thanks in advance, , sorry bad english.

sorry , all! in desperation, tried different fields in object, , didn't realize left "datanombre" instead of "datanombrecompleto" example code in question, anyway that's correct, that's original displaymember in original code, but, problem's still there :(

it should be:

cbadministrativos.displaymember = "datanombrecompleto"; 

also, consider using public properties instead of public fields.

public fields evil

change this:

public string datanombrecompleto; public int dataidusuario; 

to this:

public string datanombrecompleto { get; set; } public int dataidusuario { get; set; } 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -