:ehh: How do you search a listbox with items already inside using string and indexof function? Also, could I display the results in another listbox? What do you guys suggest. Thanks;)
Printable View
:ehh: How do you search a listbox with items already inside using string and indexof function? Also, could I display the results in another listbox? What do you guys suggest. Thanks;)
Like this:Quote:
Originally posted by anteneh
:ehh: How do you search a listbox with items already inside using string and indexof function? Also, could I display the results in another listbox? What do you guys suggest. Thanks;)
VB Code:
Imports System Imports System.Data Imports System.Data.SqlClient Public Class Form1 Inherits System.Windows.Forms.Form Private Sub btnGetData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetData.Click Dim cnCustomers As New SqlConnection("packet size=4096;integrated security=SSPI;data source=(local);" & _ "persist security info=False;initial catalog=northwind") Dim daCustomers As New SqlDataAdapter("SELECT CustomerID, CompanyName, ContactName, Address FROM Customers", cnCustomers) Dim dtCustomers As New DataTable("Customers") Dim drCustomer As DataRow daCustomers.Fill(dtCustomers) For Each drCustomer In dtCustomers.Rows Me.ListBox1.Items.Add(Convert.ToString(drCustomer("ContactName"))) Next End Sub Private Sub btnFindItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFindItem.Click Dim liCust As Object For Each liCust In Me.ListBox1.Items If Convert.ToString(liCust).IndexOf("Ana") > -1 Then Me.ListBox2.Items.Add(liCust) Next End Sub Private Sub btnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuit.Click Me.Close() End Sub End Class