We help IT Professionals succeed at work.
Get Started

Unable to filter Dataset

Last Modified: 2012-05-11
I'm having a difficult time grasping how I can filter data in a datatable using the Select method and then populate a combobox.  I've created a Private Dataset for my form that I populate on form Load.  Then when my routine runs to fill a combobox based off that I want to perform a Select against the table in the dataset but keep getting the error below.  I've attached the code as I have it...any help would be most appreciated.

Problem responseChkBoxEvents: --Message:Cannot bind to the new display member.  Parameter name: newDisplayMember--StackTrace:   at System.Windows.Forms.ListControl.SetDataConnection(Object newDataSource, BindingMemberInfo newDisplayMember, Boolean force)     at System.Windows.Forms.ListControl.set_ValueMember(String value)     at RxAssess.DynamicForm.responseChkBoxEvents(Object sender, EventArgs e) in C:\Programming\DynamicForm.vb:line 629--TargetSite:Void SetDataConnection(System.Object, System.Windows.Forms.BindingMemberInfo, Boolean)
Public Class DynamicForm
Private dsNCICriteria As New DataSet

Private Sub DynamicForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Capture data for NCI Criteria Combo Boxes
Dim conStringNCICriteria As String = "removed string;"
Dim strSQLNCICriteria As String = "select ntypeid,grade,cast(grade as nvarchar) + '   -   ' + description as description " + _
                "from nci_criteria"
Dim conNCICriteria As New SqlConnection(conStringNCICriteria)
Dim daNCICriteria As New SqlDataAdapter(strSQLNCICriteria, conNCICriteria)
daNCICriteria.Fill(dsNCICriteria, "NCICriteria")
conNCICriteria = Nothing
strSQLNCICriteria = Nothing
conStringNCICriteria = Nothing
End Sub

Sub responseChkBoxEvents(ByVal sender As System.Object, ByVal e As System.EventArgs)
If chk.Checked = True Then
                If chk.Name.Substring(chk.Name.LastIndexOf("N") + 1) <> 0 Then
                    Dim nciTypeID As String = chk.Name.Substring(chk.Name.LastIndexOf("N") + 1)
                    Dim nciFilter As String
                    nciFilter = "ntypeid = " + chk.Name.Substring(chk.Name.LastIndexOf("N") + 1)

                    Dim cbo As ComboBox = TryCast(Me.Controls(Replace(Replace(chk.Name, "CHK", "NCICBO"), "L" + z.ToString, "L" + (z + 1).ToString)), ComboBox)
                                      With cbo
                        .DataSource = dsNCICriteria.Tables("NCICriteria").Select(nciFilter)
                        .DisplayMember = "description"
                        .ValueMember = "grade"
                        .Visible = True
                        .SelectedItem = Nothing
                        .AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems
                        .AutoCompleteMode = AutoCompleteMode.Append
                    End With
                End If
End Sub

Open in new window

Watch Question
Most Valuable Expert 2012
Top Expert 2014
This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE