Adding a row to a control bound to a datasource

Hi, I have an application that consists of multiple combo boxes, list boxes, etc.  Most of the combo boxes are bound to a datasource.  What I wanted to do was add one row to each combo box with the value of "_None" so that if the user had selected an entry and then did not want the entry, there was an easy solution - select the "_None" entry.  However, when I tried to add this row to a control having a datasource I get the following error message:

"Cannot modify the Items Collection when the DataSource property is set. System.Windows.Forms"

 

I would appreciate any help with this - but, I don't want to have to store the "_None" value in the actual table that the datasource uses.

Thanks in advance!

 

Tim



Answer this question

Adding a row to a control bound to a datasource

  • Brenden

    Thanks, I appreciate the information!

     

    Tim


  • santosh k singh

    Becase you are doing binding combobox to a datasources. So you can't just add "_None" entry to the combobox.
    You need to add "_None" to your datasources first, then rebind the datasources and the combobox again.

  • Justin Niemetscheck

    I don't think you can. Unless you modify the datasources first before binding.

    Are you going to update the datasource back to database



  • anayconsultancy

    Thanks for the reply.  No, I don't want to update the database.  I should have been a little more detailed in my explanation.  Here is what I wanted to do:

    Use the .Items.Add("_None") method of the combo box to add the "_None" entry to the combo box.  Actually, I should use the .Items.Insert method to add it as the first row of the combo box.  Anyway, when I try to do the .Items.Add method on a combo box that is bound to a datasource, I get the error message I listed in my original posting.

    Hope this clarifies what I am trying to do, and I do appreciate your response!

     

    Take care,

    Tim


  • Adding a row to a control bound to a datasource