c# - Add an item to combobox before binding data from the database -
i had combobox in windows forms form retrieves data database. did well, want add first item <-please select category-> before data database. how can that? , can put it?
public category() { initializecomponent(); categoryparent(); } private void categoryparent() { using (sqlconnection con = getconnection()) { sqldataadapter da = new sqldataadapter("select category.category, category.id category", con); datatable dt = new datatable(); da.fill(dt); cbparent.datasource = dt; cbparent.displaymember = "category"; cbparent.valuemember = "id"; } }
you either add default text text
property of combobox (preferred):
cbparent.text = "<-please select category->";
or, add value datatable directly:
da.fill(dt); datarow row = dt.newrow(); row["category"] = "<-please select category->"; dt.rows.insertat(row, 0); cbparent.datasource = dt;
Comments
Post a Comment