locked
VB.net Help Me RRS feed

  • Question

  • hey Filter Listbox With Textbox help me sql server vb code please..
    Friday, March 14, 2014 7:53 PM

Answers

  • Hello,

    If you want to filter the contents of a ListBox populated with a DataTable via text in a TextBox check out my article BindingSource Find and Filtering basics to advance operations.

    The example below a ListBox is populated with data from a database table. A ComboBox provides options to filter on text on a TextBox. 

    Requires

    TextBox named txtLastName, Button named cmdFilter a button named cmdNoFilter and a ComboBox named cboConditions.

    Underlying code

    Imports DataAccess
    Public Class FilterListBoxForm
        WithEvents bsCustomers As New BindingSource
        Private Sub FilterListBoxForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Dim CustomerData As New Customers
            bsCustomers.DataSource = CustomerData.DataTable
            bsCustomers.Sort = "LastName"
            ListBox1.DisplayMember = "LastName"
            ListBox1.DataSource = bsCustomers
    
            cboConditions.DataSource = CType([Enum].GetNames(GetType(LikeOptions)), String()).ToList
    
        End Sub
        Private Sub cmdFilter_Click(sender As Object, e As EventArgs) Handles cmdFilter.Click
            bsCustomers.LikeFilter(
                "LastName",
                txtLastName.Text,
                cboConditions.Text.ToEnum(Of LikeOptions)
            )
        End Sub
        Private Sub cmdNoFilter_Click(sender As Object, e As EventArgs) Handles cmdNoFilter.Click
            CType(bsCustomers.DataSource, DataTable).DefaultView.RowFilter = ""
        End Sub
    End Class

    To use the code for Filtering and options add my LanguageExtensionsLibrary project to your solution. Also remove the Imports DataAccess statement in the code above, that is a project in my article responsible for loading data from a database.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    • Proposed as answer by Carl Cai Monday, March 17, 2014 3:04 AM
    • Marked as answer by Carl Cai Friday, March 21, 2014 6:26 AM
    Friday, March 14, 2014 9:31 PM

All replies

  • What have you tried so far?

    --
    Andrew

    Friday, March 14, 2014 7:59 PM
  • dim search as string=textbox1.text

    me.tblinfotableadapter.fillbysearchname(me.dbInfodataset.tblinfo,search,search) 

    dataset change listbox?

    • Edited by forevers Friday, March 14, 2014 8:05 PM
    Friday, March 14, 2014 8:04 PM
  • dim search as string=textbox1.text

    me.tblinfotableadapter.fillbysearchname(me.dbInfodataset.tblinfo,search,search)

    What is this mysterious "fillbysearchname" of which you write?

    To insert code, you can use the button in the editor to the right of "HTML" which looks a bit like "<>".

    --
    Andrew

    Friday, March 14, 2014 8:22 PM
  • You what? The title of this thread is POOR. It doesn't tell respondents what the problem is at all. It leaves people who are here yo help in the dark.

    Renee


    "MODERN PROGRAMMING is deficient in elementary ways BECAUSE of problems INTRODUCED by MODERN PROGRAMMING." Me

    Friday, March 14, 2014 8:48 PM
  • Hello,

    If you want to filter the contents of a ListBox populated with a DataTable via text in a TextBox check out my article BindingSource Find and Filtering basics to advance operations.

    The example below a ListBox is populated with data from a database table. A ComboBox provides options to filter on text on a TextBox. 

    Requires

    TextBox named txtLastName, Button named cmdFilter a button named cmdNoFilter and a ComboBox named cboConditions.

    Underlying code

    Imports DataAccess
    Public Class FilterListBoxForm
        WithEvents bsCustomers As New BindingSource
        Private Sub FilterListBoxForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Dim CustomerData As New Customers
            bsCustomers.DataSource = CustomerData.DataTable
            bsCustomers.Sort = "LastName"
            ListBox1.DisplayMember = "LastName"
            ListBox1.DataSource = bsCustomers
    
            cboConditions.DataSource = CType([Enum].GetNames(GetType(LikeOptions)), String()).ToList
    
        End Sub
        Private Sub cmdFilter_Click(sender As Object, e As EventArgs) Handles cmdFilter.Click
            bsCustomers.LikeFilter(
                "LastName",
                txtLastName.Text,
                cboConditions.Text.ToEnum(Of LikeOptions)
            )
        End Sub
        Private Sub cmdNoFilter_Click(sender As Object, e As EventArgs) Handles cmdNoFilter.Click
            CType(bsCustomers.DataSource, DataTable).DefaultView.RowFilter = ""
        End Sub
    End Class

    To use the code for Filtering and options add my LanguageExtensionsLibrary project to your solution. Also remove the Imports DataAccess statement in the code above, that is a project in my article responsible for loading data from a database.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    • Proposed as answer by Carl Cai Monday, March 17, 2014 3:04 AM
    • Marked as answer by Carl Cai Friday, March 21, 2014 6:26 AM
    Friday, March 14, 2014 9:31 PM