Reputation: 8302
I have a combobobox on my form, and I use the following code to populate the data from SQL Server:
cbname.DataSource = DSAssetName.Tables(0)
cbname.DisplayMember = "IDWLNAME"
cbname.ValueMember = "FIDWID"
I need the value specified in the value member for the reporting section of my app to work. This all works great and everything, but I need to add another item in the combobox "SELECT ALL", and when chosen, sends a -1 to my stored procedure so the report can show all the data. I tried manually putting "select all" in the combobox before the datasource gets set, but then it only gets overridden. Trying to add it afterward give me the error "Items collection cannot be modified when the DataSource property is set." Anybody know a good trick that can solve the problem?
Thanks
Upvotes: 2
Views: 8119
Reputation: 4193
You can add it in your SQL query something like:
Select IDWLNAME, FIDWID From tblSomeTable
UNION
Select 'SELECT ALL', -1
Upvotes: 2
Reputation: 176956
i have same issue and i tryied following it work for me : may be it help you to resolve your issue
To add "SELECT ALL" option you have to add one row in the table you are getting form the database and than bind it with the combobox.
for example :
DataRow dr = DSAssetName.Tables(0).NewRow();
dr["IDWLNAME"] = "Select All";
dr["FIDWID"] = "-1";
DSAssetName.Tables(0).Rows.AddRow(dr);
cbname.DataSource = DSAssetName.Tables(0)
cbname.DisplayMember = "IDWLNAME"
cbname.ValueMember = "FIDWID"
Upvotes: 3