Solved

Problem refilling combobox with LINQ datasource

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
How to get a file from SqlServer DB 4 29
Paging GridView 7 34
Word Template Mail merge with vb.net 4 40
Round up to 100% in .NET 10 45
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now