2 Attachment(s)
Listbox findstring issue ? why result focus at bottom of Listbox ?
Hi. Everyone. first of All sorry for my bad English. hope I can explain to what I want to do.
Advanced Thanks...
I listed All Fonts into Listbox.
Then I try to Find with TextBox1_TextChanged
When TextBox Changed Result Focus Bottom of Listbox.
How Can I show found Result on top Row of ListBox ?
Code:
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim fonts As InstalledFontCollection = New InstalledFontCollection()
Try
For Each FNT As FontFamily In fonts.Families
ListBox1.Items.Add(FNT.Name)
Next FNT
Catch
End Try
End Sub
Code:
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
If TextBox1.Text = "" Then
ListBox1.SelectedIndex = 0
End If
ListBox1.SelectedIndex = ListBox1.FindString(TextBox1.Text)
End Sub
Attachment 177507
why not like this result at top row ?
Attachment 177509
Re: Listbox findstring issue ? why result focus at bottom of Listbox ?
The ListBox only scrolls far enough that the selected item is in view. That's how it works because that's how it's designed to work. If you had read the documentation for the ListBox class then you'd already have the answer to your question, which is why you should ALWAYS read the documentation first. If you had done that then you'd have seen the TopIndex property described thusly:
Code:
Gets or sets the index of the first visible item in the ListBox.
It seems fairly obvious that, if you want that item at the top of the list, you assign the index of that item to the TopIndex property.