Ask Experts Questions for FREE Help !
Ask
    rallyboy's Avatar
    rallyboy Posts: 2, Reputation: 1
    New Member
     
    #1

    Apr 25, 2009, 05:08 PM
    ListBox and Textbox in VB.NET 2008!
    Hello everyone.

    Ok so I have in form1 a listbox1 and a textbox1. In the listbox1 I have several items and I want while I type something in the textbox1 it gives me all the similar in listbox1.

    For Example:

    I already have in listbox1 the item 'ASKME HELPDESK'. When I type in the textbox1 'ASKME', 'ASKME HELPDESK' will be selected in listbox1. Something like a searcher for the listbox.

    Im pretty sure this will be difficult but anyone who helps ill appreciate!

    Thanks, rallyboy.
    Perito's Avatar
    Perito Posts: 3,139, Reputation: 150
    Ultra Member
     
    #2

    Apr 26, 2009, 01:43 PM

    Double-click on textbox1 to create a handler. At the end, it will say "Handles TextBox1.TextChanged".

    Write the handler as follows:

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
    Dim TestStr As String = TextBox1.Text.ToLower ' test regardless of case.
    For I As Integer = 0 To ListBox1.Items.Count - 1
    If ListBox1.Items(I).ToString.ToLower.IndexOf(TestStr ) = 0 Then ' also ignore case. Index = 0 means it matches the first of the string.
    ListBox1.Text = ListBox1.Items(I).ToString ' Pin the listbox to the found item.
    Exit For ' Required if you wish to stop on the first match
    End If
    Next
    End Sub
    End Class

    Viola. Boy, that was tough! Maybe you should pay me for my services ;):D
    ScottGem's Avatar
    ScottGem Posts: 64,966, Reputation: 6056
    Computer Expert and Renaissance Man
     
    #3

    Apr 26, 2009, 03:05 PM
    Quote Originally Posted by Perito View Post
    Viola. Boy, that was tough! Maybe you should pay me for my services ;):D
    There is a way to setup your profile to add a Support this Member link that lets people send you a donation via Paypal. It happens rarely, but it does happen.

    But the main reason I'm posting is I wonder how similar lists boxes in VB are to the ones in VBA. The reason I ask is that Access Comboboxes have an AutoExpand property that, when set to Yes, do exactly what the OP wants. As they type into the combo, it will bring up the first matching item in the list.
    Perito's Avatar
    Perito Posts: 3,139, Reputation: 150
    Ultra Member
     
    #4

    Apr 26, 2009, 03:35 PM
    .NET listboxes don't have the autoexpand property. Comboboxes are quite different in .NET. They don't have the AutoExpand property any longer. I think it's mostly for flexibility in programming, and for consistency throughout the .NET framework.
    rallyboy's Avatar
    rallyboy Posts: 2, Reputation: 1
    New Member
     
    #5

    Apr 27, 2009, 04:30 AM
    Quote Originally Posted by Perito View Post
    Double-click on textbox1 to create a handler. At the end, it will say "Handles TextBox1.TextChanged".

    Write the handler as follows:

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
    Dim TestStr As String = TextBox1.Text.ToLower ' test regardless of case.
    For i As Integer = 0 To ListBox1.Items.Count - 1
    If ListBox1.Items(i).ToString.ToLower.IndexOf(TestStr ) = 0 Then ' also ignore case. Index = 0 means it matches the first of the string.
    ListBox1.Text = ListBox1.Items(i).ToString ' Pin the listbox to the found item.
    Exit For ' Required if you wish to stop on the first match
    End If
    Next
    End Sub
    End Class

    Viola. Boy, that was tough! Maybe you should pay me for my services ;):D
    Thanks VERY much ! You helped my loads! Thanks again, appreciated it :)

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Cannot write in textbox in IE in windows XP [ 3 Answers ]

I am not able to write in internet explorer in windows explorer for last few days. It is windows XP with SP2. Radio buttins and othen stuff is working fine. I run Ad-aware and AVG anti-virus with zero virus. Can somebofy help me out.

Listbox and textbox in vb.net [ 3 Answers ]

Hi there, I wonder if anyone can help. I have a listbox and a textbox. At runtime I already have a list of items in the listbox. When I double click on these items its needs to appear in the textbox. At the moment I have the code that, when I double click on the item in the listbox ONLY one item...

Textbox Size Limit, IE [ 2 Answers ]

Does anyone have an explanation to why textbox size tag parameter doesn't work on any internet explorer versions but does apply on Firefox and Opera latest versions? I want to limit how wide the textbox stretches but it doesn't work on IE.

ListBox problem [ 1 Answers ]

If lstSchedule.Items.Contains((0)) = True Then objWriter.WriteLine((0)) End If If lstSchedule.Items.Contains((1)) = True Then objWriter.WriteLine((1)) -----------------------until objWriter.WriteLine((7))--------------------- is this...


View more questions Search