Chủ Nhật, 4 tháng 9, 2016

VB.NET Tutorial : How to Search/Fillter Items in a ListBox


Vb.NET tutorial for beginners - How we can add some values / items into a ListBox component and then search or fillter it using a TextBox in vb.net programming languages? we can create simple application that contains the match will be selected at the Listbox.

At your visual studio, create new project and at the form1.vb add some component like a TextBox, Button and a ListBox component.

Write all source code serach items in a ListBox below

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ' Add items into ListBox
        With ListBox1.Items
            .Add("Harison Matondang") ' add more string
            .Add("www.hc-kr.com") ' add more string
            .Add("budi") ' add more string
            .Add("beni") ' add more string
            .Add("Indonesia") ' add more string
        End With
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim search As String
        ' doing loops here
        For x As Integer = 0 To ListBox1.Items.Count - 1
            search = ListBox1.Items.Item(x)
            If InStr(search.ToLower, TextBox1.Text.ToLower) Then
                ' show the result here
                ListBox1.SelectedItem = search
            End If
        Next
    End Sub
End Class

How to Search/Fillter Items in a ListBox

Video Tutorial serach items in a ListBox below



Download full source code here http://bit.ly/2bXq21d

Không có nhận xét nào:

Đăng nhận xét