troubleshooting Question

Two Different Filters for Two Different Listboxes

Avatar of Declan Basile
Declan BasileFlag for United States of America asked on
Visual Basic.NET.NET Programming
3 Comments1 Solution86 ViewsLast Modified:
I want one listbox on a vb.net form to display records in a datatable that have "Selected = 0" (note: "Selected is a field in the datatable) and another listbox on the form to display records in the datatable that have "Selected = 1".  I wrote the posted code, but when I set the filter for bs2 it appears to affect both listboxes, even though the first listbox's datasource is bs1.  Why does this happen, and how can I set a different filter for each listbox?

    Private Sub SelectItems_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Dim cn As New SqlConnection(strConn)
        Dim SQL As String

        SQL = "SELECT UserId As Id, FullName As Name, 0 As Selected FROM Users WHERE Terminated = 0"
        Using da As New SqlDataAdapter(SQL, cn)
            da.Fill(dt)
        End Using
        bs1.DataSource = dt
        bs1.Sort = "Name"
        bs1.Filter = "Selected = 0"
        lbxUnSelectedItems.DataSource = bs1
        lbxUnSelectedItems.ValueMember = "Id"
        lbxUnSelectedItems.DisplayMember = "Name"

        bs2.DataSource = dt
        bs2.Sort = "Name"
        bs2.Filter = "Selected = 1"
        lbxSelectedItems.DataSource = bs2
        lbxSelectedItems.ValueMember = "Id"
        lbxSelectedItems.DisplayMember = "Name"

        cn = Nothing

    End Sub
ASKER CERTIFIED SOLUTION
Shaun Kline
Lead Software Engineer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros