winforms - insert item in combobox after binding it from a Dataset in c# -


i have insert "select" @ top after combobox bound dataset.i tried this isn't working.throws error "dataset doesn't have definition cast".i think not using properly.commented code part tried not working.

cmbcategory.datasource = dscat.tables[0]; cmbcategory.displaymember = "categoryname"; cmbcategory.valuemember = "id"; // cmbcategory.items.add("select"); // cmbcategory.selectedtext = "select"; // cmbcategory.datasource =(new object[] { "select" }).concat(this.livereportingdalc.getcategoriesbytype(categorytype.registrationtype).cast<object>()); 

you have insert object databinding rather combobox. can't insert directly combobox.

you can use :

datatable dt = new datatable(); dt.columns.add("id", typeof(int)); dt.columns.add("categoryname"); cmbcategory.displaymember = "categoryname"; cmbcategory.valuemember = "id"; cmbcategory.datasource = dt; datarow dr = dt.newrow(); dr["categoryname"] = "select"; dr["id"] = 0; dt.rows.insertat(dr, 0); cmbcategory.selectedindex = 0; 

this straight forward example.


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -