Solved

Problem refilling combobox with LINQ datasource

Posted on 2011-03-11
5
721 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
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 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.

828 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