Friday, 15 March 2013

c# - Combo box custom items and data bound items -



c# - Combo box custom items and data bound items -

i've made combo box , added item , loaded info datasource function getbs() returns bindingsource.

combobox1.items.insert(0, "all"); combobox1.datasource = getbs();

when comment datasource shows item "all", when code shows info doesn't show attribute "all". there way create together? show attribute "all" , rest of data?

msdn says

a info source can database, web service, or object can later used generate data-bound controls. when datasource property set, the items collection cannot modified.

so options now?

bindingsource getbs(bool addall = false) { ...... con.open(); cmd = new sqlcommand("usppodruznicaselect", con); da.selectcommand = cmd; da.selectcommand.commandtype = commandtype.storedprocedure; da.fill(dbtable); if(addall) { datarow dr = dbtable.newrow(); dr["itemid"] = 0; dr["itemdata"] = "all"; dbtable.rows.insertat(dr, 0); } bsource.datasource = dbtable; con.close(); homecoming bsource; }

adding straight datatable returned sp. of course of study don't know exact names of fields involved in table, give idea. perchance have other problems if sp returns table more fields , these fields not nullable. in case need add together dummy value these field in new row.

c# combobox datasource items

No comments:

Post a Comment