943,632 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 6720
  • VB.NET RSS
Nov 9th, 2006
0

Updating a databound combobox

Expand Post »
Hi, guys!

Got a problem here.

I have a form that when it loads spawns a thread which in turn fills a publicly declared dataset with a table by a dataadapter and then binds a field from the table to a combobox.

vb Syntax (Toggle Plain Text)
  1. combobox1.DisplayMember = "fieldName"
  2. combobox1.ValueMember = "fieldName"
  3. combobox1.DataSource = dataset1.Tables("<tablename>")

This works like a charm.
I can fetch existing records and manipulate the data (edit and update) perfectly.

But this is the crux.
When I clear the form, add information and save it as a new record, everything is stored in the database as it should and I explicitly use the method dataset1.Tables("<tablename>").AcceptChanges after the update to the server.
However, the bound combobox is not updated with the new information.

I have the impression that if you add a record to a table that is bound to a control and force the update on the table, that information is immediatly available to the control.

I've been googling for an answer for three days without much luck.
My last attempt at this involved iterating through the table with for each row as dataset1.table("<tablename>").Rows. But that took too long and screwed up the thread.

Can you help me find a solution to this?

I connect to a MSSQL 2000 server and use untyped datasets, all by code.
Last edited by Oxiegen; Nov 9th, 2006 at 4:56 am.
Similar Threads
Reputation Points: 87
Solved Threads: 128
Practically a Master Poster
Oxiegen is offline Offline
652 posts
since Jun 2006
Nov 10th, 2006
0

Re: Updating a databound combobox

I solved it myself using the dataview class.

vb Syntax (Toggle Plain Text)
  1. Dim dbView As DataView
  2. dbView = new DataView(DataSet1.Tables("<tablename>"))
  3. dbView.Sort = "id DESC"
  4.  
  5. cmbRegID.DisplayMember = "column2"
  6. cmbRegID.DataSource = dbView
  7. cmbRegID.SelectedIndex = 0

Now everytime I add (or delete) items from the datatable it shows in the combox right away (and selects the latest added item).
Reputation Points: 87
Solved Threads: 128
Practically a Master Poster
Oxiegen is offline Offline
652 posts
since Jun 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Timer Control Help
Next Thread in VB.NET Forum Timeline: my vb video turtorial for beginers(coming soon)





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC