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

前端 未结 3 1447
眼角桃花
眼角桃花 2020-12-03 05:41

I have to insert \"Select\" at top after combobox is bound from dataset.i tried this but it isn\'t working.Throws error \"dataset doesn\'t have any definition for cast\".I t

3条回答
  •  独厮守ぢ
    2020-12-03 06:20

    You cannot add items to a ComboBox after binding it to a data source. To add or remove items from a ComboBox with a bound data source, you have to do it through data source itself.

    You can insert a DataRow into your table and it will be automatically added to your ComboBox. Try the following:

     DataRow dr = dsCat.Tables[0].NewRow();
     dr["CategoryName"] = "Select";
     dr["ID"] = 123;// Some ID
     dsCat.Tables[0].Rows.Add(dr);
    

提交回复
热议问题