vb.net - Need to bind/populate combobox in WPF forms, ideally with value and display -
my application other reasons isn't set mvvm architecture , i'm not able @ time. thing need modify combobox populated database (it stored in oracledatareader). programmatically add items combobox looping through oracledatareader, or bind in way.
public sub loadlocationcombo() dim rs oracledatareader dim dt new datatable() dim dr datarow dim lstitems new arraylist rs = objclsdb.locationcombo dt.load(rs) dt.columns("description").allowdbnull = true dt.columns("value_id").allowdbnull = true dt.columns("description").defaultvalue = "" dt.columns("value_id").defaultvalue = 0 dr = dt.newrow dr("description") = "" dr("value_id") = 0 dt.rows.insertat(dr, 0) cbolocation.itemssource = dt.defaultview cbolocation.displaymemberpath = "description" cbolocation.selectedvaluepath = "value_id" end sub
that current method, i'm trying add blank row @ top well. makes combo have looks multiple rows nothing in selected value , nothing displays.
edit: if remove cbolocation.displaymemberpath , .selectedvaluepath combobox filled bunch of system.data.common.datarecordinternal
first, defaultview of datatable return object of type dataview, , dataview not have properties called "description" or "value_id". that's why nothing selected, , nothing displayed.
you might build list , fill datatable values, example:
dim listtofillcombo new list(of keyvaluepair(of integer, string)) each dr datarow in dt.rows listtofillcombo .add(new keyvaluepair(of integer, string)(cint(dr("value_id")), dr("description").tostring)) next
then combobox binding
cbolocation.itemssource = listtofillcombo cbolocation.displaymemberpath = "value" cbolocation.selectedvaluepath = "key"
Comments
Post a Comment