Minggu, 02 Oktober 2011

Syntax untuk buat Search List Box

Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        With ListBox1.Items
            .Add("My name is Jimmy")
            .Add("I am from California")
            .Add("I go to UCLA")
            .Add("I like porgramming in VB 2008")
            .Add("I love Visual Basic language")
            .Add("This tutorial shows you how to search a listbox ")
        End With
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ListBox2.Items.Clear()
        Dim count As Integer = (ListBox1.Items.Count - 1)
        Dim words As String
        For a = 0 To count
            words = ListBox1.Items.Item(a)
            If InStr(words.ToLower, TextBox1.Text.ToLower) Then
                ListBox2.Items.Add(words)
            End If
        Next
    End Sub
End Class

Tidak ada komentar:

Posting Komentar