User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the VB.NET section within the Software Development category of DaniWeb, a massive community of 427,680 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,298 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our VB.NET advertiser: Programming Forums
Views: 2788 | Replies: 1
Reply
Join Date: Jun 2006
Location: Sweden
Posts: 45
Reputation: Oxiegen is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 2
Oxiegen Oxiegen is offline Offline
Light Poster

Question Updating a databound combobox

  #1  
Nov 9th, 2006
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.

  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 3:56 am.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2006
Location: Sweden
Posts: 45
Reputation: Oxiegen is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 2
Oxiegen Oxiegen is offline Offline
Light Poster

Solution Re: Updating a databound combobox

  #2  
Nov 10th, 2006
I solved it myself using the dataview class.

  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).
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb VB.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the VB.NET Forum

All times are GMT -4. The time now is 11:16 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC