Solved

Problem refilling combobox with LINQ datasource

Posted on 2011-03-11
5
720 Views
Last Modified: 2012-05-11
Simple code that works the first time for a combobox:

        Dim dbCPI As New MBCPIDataContext

        Dim cnum = From CPI In dbCPI.view_CaseNumbers Select CPI.CaseNumber Distinct

        Me.cmb_CaseNumber.DataSource = cnum
        Me.cmb_CaseNumber.DisplayMember = "CaseNumber"
        Me.cmb_CaseNumber.Sorted = True

I want users to be able to click on a button to refill the combobox if an entry is missing and may have been added to the underlying SQL table.  I currently have the button set to just rerun this code.  But it does not refill the combobox, even though I know the underlying data has changed.  If I first set the datasource to Nothing, then the combobox comes back empty, and never fills. I don't think this is really a LINQ issue.  I can see definitively that the LINQ is returning the right dataset, it's just not getting loaded into the combobox.

Help appreciated.

Thanks.
0
Comment
Question by:kennygeorge
  • 4
5 Comments
 
LVL 17

Expert Comment

by:nepaluz
ID: 35113112
call

Me.cmb_CaseNumber.DataSource = Nothing

Open in new window


Before you re-populate.
0
 

Author Comment

by:kennygeorge
ID: 35114219
I probably put have should this as code to make it more clear, but I did say above the I had already tried that:

"If I first set the datasource to Nothing, then the combobox comes back empty, and never fills"

Any other ideas?  Or ideas about how I might be implementing that wrong.  I tried it with that line right before the code I gave, and it didn't work.  Instead of an unchanged combobox list, I had a completely empty combobox list.
0
 

Accepted Solution

by:
kennygeorge earned 0 total points
ID: 35114509
I finally located a similar posting once I added WinForm to my search terms.  The solutions was to hide and unhide the control:

Dim dbCPI As New MBCPIDataContext

Dim cnum = From CPI In dbCPI.view_CaseNumbers Select CPI.CaseNumber Distinct

Me.cmb_CaseNumber.Visible = False
Me.cmb_CaseNumber.DataSource = cnum
Me.cmb_CaseNumber.DisplayMember = "CaseNumber"
Me.cmb_CaseNumber.Sorted = True
Me.cmb_CaseNumber.Visible = True

0
 

Author Comment

by:kennygeorge
ID: 35114544
Went back and tested once more after closing, and it no longer worked.  Aargh!
0
 

Author Closing Comment

by:kennygeorge
ID: 35145600
Odd to give myself a grade, but I don't see any other way to get this into the database.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question