Solved

Problem refilling combobox with LINQ datasource

Posted on 2011-03-11
5
726 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

630 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