Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Problem refilling combobox with LINQ datasource

Posted on 2011-03-11
5
Medium Priority
?
728 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

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…
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 …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

730 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