Hi im Paul,
im from Brasil and im searching something about it, and searching in google i found this forum, so i post this reply to say that u dont need use API.
U can use :
ListBox1.SelectedIndex = (ListBox1.FindString(TextBox1.Text))
Try this... Drop a listview and a textbox on a form, then put this code in:
Public Class Form1
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
ListView1.SelectedItems.Clear()
For ix As Integer = 0 To ListView1.Items.Count - 1
Dim ls As String = ListView1.Items(ix).Text
If String.Compare(ls.Substring(0, TextBox1.Text.Length), TextBox1.Text, True) = 0 Then
ListView1.Items(ix).Selected = True
ListView1.Items(ix).EnsureVisible()
Exit For
End If
Next ix
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
With ListView1
.Columns.Add("Abadaba", 70)
.View = View.Details
.HideSelection = False
.Items.Add("ABC")
.Items.Add("ABD")
.Items.Add("ACD")
.Items.Add("BCD")
.Items.Add("BDE")
End With
End Sub
End Class
This is fantastic, I was wondering though how I could add a value??? so that when you select the item, an id would be set to run in an SQL query???? i have this working with a listbox, but i would like to add this with the list view??????
[Highlight=VB] Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Populates the list box using DataSource.
' DisplayMember is used to display just the long name of each state.
Dim USStates As New ArrayList()
USStates.Add(New USState("Alabama", "AL"))
USStates.Add(New USState("Washington", "WA"))
USStates.Add(New USState("West Virginia", "WV"))
USStates.Add(New USState("Wisconsin", "WI"))
USStates.Add(New USState("Wyoming", "WY"))
AddHandler ListBox1.SelectedValueChanged, AddressOf ListBox1_SelectedValueChanged
ListBox1.DataSource = USStates
ListBox1.DisplayMember = "LongName"
ListBox1.ValueMember = "ShortName"
end sub
Private Sub ListBox1_SelectedValueChanged(ByVal sender As Object, ByVal e As EventArgs)
If ListBox1.SelectedIndex <> -1 Then
TextBox3.Text = ListBox1.SelectedValue.ToString()
End If
End Sub 'ListBox1_SelectedValueChanged
This is what I have but need to add this to the listview, but the selected value isn't available. I'm trying to avoid an array with the values set, and using the selected index .....
Figured it out, I used the keypress property, ahehaeahe
Last edited by ookied; Nov 18th, 2006 at 08:02 PM.