IT KNOWLEDGE

IT KNOWLEDGE
BC

Saturday, July 11, 2015

Search in ListBox (VB.Net)

In this tutorial, I will show you how to create an application to search data from ListBox. I'll use 4 controls to add on form:

  1. TextBox1
    • Text=""
    • Name="TxtSearch"
    • Font Size=12

  1. Button1
    • Text="Search"
    • Name="CmdSearch"
    • Font Size=12
  2. ListBox1:
    • Name:"DataListBox1"
    • Font Size=12
  3. ListBox2
    • Name="DataListBox2"
    • Font Size=12

Code
Public Class SeachListbox

    Private Sub SeachListbox_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        With DataListBox1.Items
            .Add("Business Management")
            .Add("Computer Science")
            .Add("Tourism Study")
            .Add("Law")
            .Add("Marketing")
            .Add("Electronic")
            .Add("Management")
            .Add("Engineering")
        End With
    End Sub

    Private Sub CmdSearch_Click(sender As Object, e As EventArgs) Handles CmdSearch.Click
        DataListBox2.Items.Clear()
        Dim count As Integer = (DataListBox1.Items.Count - 1)
        Dim StringA As String
        Dim StringB As String
        Dim spaceStringCounter As Integer = 0
        For i = 0 To count
            StringA = DataListBox1.Items.Item(i)
            MessageBox.Show(StringA)
            For j = 0 To StringA.Length - 1
                If spaceStringCounter >= 2 Then
                    StringB += StringA.Substring(j, 1)
                ElseIf StringA.Substring(j, 1) = Chr(32) Then
                    spaceStringCounter += 1
                End If
            Next
            If InStr(StringB, TxtSearch.Text) Then
                DataListBox2.Items.Add(DataListBox1.Items.Item(i))
            End If
            StringA = Nothing
            spaceStringCounter = 0
            StringB = Nothing
        Next
    End Sub
End Class


Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Powered By: itech-9999

0 comments: