Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 2010 > BOOK: Visual Basic 2010 Programmer's Reference
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Visual Basic 2010 Programmer's Reference
This is the forum to discuss the Wrox book Visual Basic 2010 Programmer's Reference by Rod Stephens; ISBN: 9780470499832
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Visual Basic 2010 Programmer's Reference section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old March 21st, 2013, 11:02 AM
Registered User
Points: 37, Level: 1
Points: 37, Level: 1 Points: 37, Level: 1 Points: 37, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2013
Location: Tampa Bay
Posts: 9
Thanks: 1
Thanked 0 Times in 0 Posts
Default Re-Populate a linked ComboBox

I have a form with a ComboBox. The ComboBox contains entries from a Query linked to the Form. The entries are dynamic and are maintained by a secondary form that I open in 'Dialog' mode. When I add a new record to the underlying Table through the 'maintenance' form, the ComboBox does not reflect this, however (and there's the weird part), when I delete a record from the underlying table in the maintenance form, the ComboBox reflects this correctly.

Here is the section of code where I call the maintenance for and 'attempt' to update the ComboBox (the ComboBox being maintained contains Chapter information for specific books, so the cboBooks combo contains book names, and cboChapters contains available chapters in the book...which is the function of the Maintenance form):

QryChaptersBindingSource.RemoveFilter()
frmBookMaintenance.ShowDialog()
frmBookMaintenance.Dispose()
Me.Invalidate()
QryChaptersBindingSource.ResetBindings(False)
QryChaptersBindingSource.ResumeBinding()
QryChaptersTableAdapter.Fill(Me.MyAppDataSet.qryCh apters)
QryChaptersBindingSource.Filter = "[Book] = " & cboBooks.SelectedValue
cboChapter.ResetText()

The maintenance form contains a DataGridView of each Book's chapters (and info each chapter). The ComboBox on the main form contains an entry for each chapter found in the Book (that is maintained by the maintenance form).

Again, when I delete a Chapter in the Maintenance form, the ComboBox has correct entries in it, when I add a Chapter in the Maintenance form, the ComboBox does not contain the new Chapter. When I close the Main form and re-open it, the new chapter does appear however.

I'm stumped.

Paul D. Goldstein
Reply With Quote
  #2 (permalink)  
Old March 21st, 2013, 12:48 PM
Rod Stephens's Avatar
Wrox Author
Points: 3,141, Level: 23
Points: 3,141, Level: 23 Points: 3,141, Level: 23 Points: 3,141, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 640
Thanks: 2
Thanked 96 Times in 95 Posts
Default

I'm not sure why it's doing that. Are you committing the changes to the database either or both times?

In any case, I think if you set the ComboBox's data source to nothing and then set it back to the table, it may work.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
Reply With Quote
  #3 (permalink)  
Old March 21st, 2013, 06:14 PM
Registered User
Points: 37, Level: 1
Points: 37, Level: 1 Points: 37, Level: 1 Points: 37, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2013
Location: Tampa Bay
Posts: 9
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Okay,
I've tried a few things (none which are working), but I did find something and maybe you could point me in the right direction.
I have two tables that I'm dealing with: 1) tblBooks 2) tblChapters

tblBooks contains all of the names of the available books
tblChapters contains 4 fields 1) RecordKey (an autonum field), 2) Book (pointing to the RecordKey of tblBooks), 3) Chapter (the Chapter #), 4) Verses (the # of verses in the Chapter)
Not that any of this is of great importance

There are two ComboBoxes on the Main form: 1) Book (name), 2) Chapter#

The subForm (opened in dialog mode), maintains the Chapter/Verse info for each book (through the use of a ComboBox with the Bookname, and a DataGridView of the Chapter/#verses in the selected book of the subForm).

The subForm has a save button with the following code:
Me.Validate()
DataGridView1.EndEdit()
builder.QuotePrefix = "["
builder.QuoteSuffix = "]"
builder.GetUpdateCommand()

Try
Me.TblChaptersTableAdapter.Update(Me.TblChaptersBi ndingSource.DataSource)
Catch exc As OleDbException
Debug.Print("daChapters.Update 'Error': " & exc.Message & ", " & builder.ToString)
End Try


I'm pretty sure that it's working because when I re-open the subForm the new data is still there (also when I close and re-open the MainForm (while the program is still running), the ComboBox populates correctly).

Here's the part I'm not sure of, if you look at my original question (where I have the code that opens the form in showDialog mode, I don't call the tblChapters data adapter: tblChaptersDataAdapter, I call it qryChaptersDataAdapter, because in the main form, the ComboBox lists the Chapters in sorted order.
So there are two BindingSources talking to the same table in the Database:
tblChapters -> SELECT tblChapters.* FROM tblChapters (used by the subForm and sorted by the DataGridView)
qryChapters -> SELECT tblChapters.* FROM tblChapters SORTED BY tblChapters.Chapter (used by the main form).

Okay, so what do I need to do? Should I use qryChapters in the subForm, or how do I sort the Chapter#s in the ComboBox if I use tblChapters instead of qryChapters as the BindingSource

This is getting weird!

Paul
Reply With Quote
  #4 (permalink)  
Old March 25th, 2013, 11:00 AM
Rod Stephens's Avatar
Wrox Author
Points: 3,141, Level: 23
Points: 3,141, Level: 23 Points: 3,141, Level: 23 Points: 3,141, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 640
Thanks: 2
Thanked 96 Times in 95 Posts
Default

I think you should be okay as long as the query, table, etc. all point to the same data source.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
Reply With Quote
  #5 (permalink)  
Old March 25th, 2013, 06:34 PM
Registered User
Points: 37, Level: 1
Points: 37, Level: 1 Points: 37, Level: 1 Points: 37, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2013
Location: Tampa Bay
Posts: 9
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Yes, there is only one table in the Database that I am using:
tblChapters, with the following fields: RecordKey, Book, Chapter, Verses.
So the two definitions found in the Database's Dataset pointing to the same table are:
tblChapters (SELECT tblChapters.* FROM tblChapters)
And qryChapters (SELECT tblChapters.* FROM tblChapters SORTED BY qryChapters.Chapter), the ComboBox then has a Filter (via the BindingSource) that points to only one Book.

So my next question is: What needs to be done (after I close the form), to "refresh" the link back to the table?

If you look at the original code, I open the form using .ShowDialog().
I then use .Dispose() Is this the right thing to do?

Here's where I'm allowing myself to be confused. I have:
QryChaptersDataAdapter (how do I force this to update in the main form)
QryChaptersBindingSource (other than 'ResetBindings(False)' is there something else that I should do?)
The Dataset object itself (which VS2010 calls: _The_Hazzan_s_DesktopDataSet).

One more thing. In my original example, I mentioned that when I added a new row to the table, the ComboBox didn't reflect this, but when I deleted a row, the ComboBox showed the correct number of Chapters available. Now, when I change the ResetBindings(False) to (True), I get the opposite effect: when I add a new row it shows up in the ComboBox, but when I delete a row, it doesn't.

I just ran another test (maybe it's a timing thing?). I deleted a row (and it didn't show up), then I deleted another row, and the correct value appeared in the ComboBox (I started with 9, I deleted a row and closed the subForm and 9 still appeared. Then I opened the subForm and deleted another row, closed the form, and a 7 appeared in the ComboBox). Should there be some way of waiting for the Database to update before trying to populate the ComboBox again? Am I just barking up the wrong tree?

I'll be out for a couple of days, and may not respond until Thursday.

Take care,
Paul Goldstein
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to populate combobox with xml using VB? QuadFather XML 8 April 7th, 2010 09:07 AM
Populate combobox from ADO recordset - RESOLVED! robzyc Access VBA 8 May 23rd, 2008 01:07 AM
Populate ListView From ComboBox Select eusanpe C# 4 August 20th, 2007 06:49 PM
populate combobox in xsl mausumee XSLT 2 February 23rd, 2007 05:37 PM
populate data in a windows form combobox from a da anibiswas General .NET 0 March 4th, 2005 02:57 PM



All times are GMT -4. The time now is 11:17 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.