Results 1 to 2 of 2

Thread: Listbox findstring issue ? why result focus at bottom of Listbox ?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2018
    Posts
    77

    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
    Name:  Ekran Alıntısı.PNG
Views: 412
Size:  8.7 KB

    why not like this result at top row ?
    Name:  Ekran Alıntısı2.PNG
Views: 409
Size:  13.8 KB

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width