I have a combo box that is bound to a table in a dataset. When I add, modify or delete a record in the dataset, i need that to be reflected in the combo box. I use the generated functions of the dataset. The database itself changes accordingly but not the bound control. I am using Visual C++ in VS 2005. All the databinding was done with drag and drop in the visual designer.
Thanks in advance for your help
this is the code that i am using. most of it was generated when i built the form.
private: System::Windows::Forms::BindingSource^ companiesBindingSource1; this->companiesBindingSource1 = (gcnew System::Windows::Forms::BindingSource(this->components)); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->companiesBindingSource1))->BeginInit(); //sets up binding source this->companiesBindingSource1->DataMember = L"Companies"; this->companiesBindingSource1->DataSource = this->CallSheetDataSet; //binds here this->deleteRec2->DataSource = this->companiesBindingSource1; this->deleteRec2->DisplayMember = L"Name"; this->deleteRec2->FormattingEnabled = true; this->deleteRec2->Location = System::Drawing::Point(115, 52); this->deleteRec2->Name = L"deleteRec2"; this->deleteRec2->Size = System::Drawing::Size(197, 21); this->deleteRec2->TabIndex = 11; this->deleteRec2->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::comboBox10_SelectedIndexChanged); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->companiesBindingSource1))->EndInit(); //on button press deletes item selected in combobox from database //Need to refresh data in combobox once delete is complete private: System::Void deleteButton_Click(System::Object^ sender, System::EventArgs^ e) { System::String^ deleteType = deleteRec1->GetItemText(deleteRec1->Items[deleteRec1->SelectedIndex]); if(deleteType == "Company"){ this->CompaniesTableAdapter->Delete(deleteBox1->Text); //end edit doesnt work here this->companiesBindingSource1->EndEdit(); this->deleteRec2->DataSource = this->companiesBindingSource1; //tried forcing refresh here, doesnt work this->companiesBindingSource->ResetBindings(false); this->companiesBindingSource1->ResetBindings(false); }//if company