c# - Showing a particular value in combobox -


it looks simple problem i'm stuck - here problem:

i have combobox cmbconstriant

if (!string.isnullorempty(m_link.constraintlayerlinktype)) {     bindinglist<myconstraintobj> allconstraints = getallconstraintlinks(m_project.networklayers);     cmbconstriant.datasource = allconstraints;     cmbconstriant.displaymember = "value";     cmbconstriant.selectedtext=m_link.constraintlayerlinktype;   } else {     bindinglist<myconstraintobj> allconstraints = getallconstraintlinks(m_project.networklayers);     cmbconstriant.datasource = allconstraints;     cmbconstriant.displaymember = "value"; } 

the values binding when m_link.constraintlayerlinktype empty.

when has string should show value , other values should there in drop down. m_link.constraintlayerlinktype user selected value dropdown.

it showing same result both case

try

cmbconstriant.selectedindex = cmbconstriant.items.indexof(m_link.contraintlayerlinktype); 

edit:

i see you're adding items of class myconstraintobj combo. in myconstraintobj class add -

public override bool equals(object obj) {     string scomparestring = obj string;     if (scomparestring == null) return false;     return constraintlayerlinktype == scomparestring; } 

indexof function compares item you're passing (string) every other item in combobox, since of type myconstraintobj, comparing them incorrectly, function force comparison of variable constraintlayerlinktype string value pass.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -