|
-
Mar 15th, 2009, 10:20 PM
#1
Thread Starter
Member
[RESOLVED] [2008] Combo Update
I have a form wich contains a combobox that is filled from a sql databse table,
this combo is named ManufacturerComboBox.
If a manufacturer is not already entered into the database you can click a label and it invokes another form called Add Manufacturer.
everything works ok except after i enter a new manufacturer into the Add Manufacturer datagrid it doesnt refresh into the ManufacturerComboBox unless i exit the Form and re-enter.
What is a good way to repopulate this combo box?
The combo box is in unbound mode and is populated by code:
With ManufacturerComboBox
.DisplayMember = "Manufacturer"
.ValueMember = "ManufacturerID"
.DataSource = GetManufacturers() 'public sub
End With
In the Add Manufacturer form in the closing event:
Me.AddManDataGridView.Update()
Me.AddManManufacturersTableAdapter.Update(Me.MemKingDataSet.AddManManufacturers)
AuditItem.Refresh() ' audit item is the name of the form that the combo box resides.
I tried to use AuditItem.ManufacturerComboBox.update() in the form closing event but it didnt work, what is the best wat to handle this?
-
Mar 15th, 2009, 11:53 PM
#2
Re: [2008] Combo Update
First up, your ComboBox is NOT unbound. Data-binding isn't done just in the designer. All the designer does is generate code for you, so you can write the same code and bind yourself. If you set the DataSource property then you're binding, plain and simple.
As for the question, the problem is that you're getting the data and binding it to the ComboBox but then you make changes to some other data. You should be binding the ComboBox to the same data that you make changes to and then save. Alternatively, you can simply re-get the data to bind to the ComboBox. You called GetManufacturers to populate it in the first place. Just call GetManufacturers again.
-
Mar 16th, 2009, 12:10 AM
#3
Thread Starter
Member
Re: [2008] Combo Update
Ive been trying to do that, the problem is, i am not 100% sure what event to place the code into.
A separate window opens, i enter the new manufacturer, then i close the window. I called getmanufacturers() on the closing event in the new manufacturer window, is this the right place to put it?
is there a way to tell the parent window that the add manufacturer window is open and when it closes to the call getmanufacturers()?
-
Mar 16th, 2009, 12:14 AM
#4
Thread Starter
Member
Re: [2008] Combo Update
Also i cant really bind the combo box to that data-source because it is dynamically populated according to an ID column in the database.
Each item contains computer specs, so if i need to pull that specific item up it fills the combo boxes and text fields according to what is contained in the database for that ID Row. I hope that makes sense.
-
Mar 16th, 2009, 12:20 AM
#5
Re: [2008] Combo Update
I assume that you're displaying this other window by calling ShowDialog. I would simply test the result of ShowDialog and, if it's OK, repopulate the ComboBox.
I'm not sure what you mean by post #4. If you mean that the item selected in the ComboBox is determined by a different binding then that should be no problem. The selected item is still going to exist after to rebind so it should be reselected automatically.
-
Mar 16th, 2009, 12:47 AM
#6
Thread Starter
Member
Re: [2008] Combo Update
Actually i was foolishly using .show() and not showdialog().
Anyway i added the OK button and the Cancel button to the AddManufacturer form and added the appropriate code the the OK and it works like a champ.
Thank You very much!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|