Search a checkedlistbox using a textbox

Hello, i have a textbox i want to write in, as soon as i write f.eks "f" i want the checkbox to move to the "f" section of the box, and as soon as i write "fr" move to the "fr" etc etc

checkedlistbox1.text = textbox1.text             does not work, since i need to write the whole name in the textbox before it jumps to the name f.eks i cant write "fr" and the box jumps to "frank", it doesnt jump there until i write the whole name in the textbox, which is completly wrong, i want it to check every letter as soon as i write it
LVL 3
leeds2000Asked:
Who is Participating?
 
ZeonFlashConnect With a Mentor Commented:
That looks like it should work, yes...and I believe that's also what I posted in the other thread.  Glad to hear you got it working.
From http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_22966224.html:
 
Private Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
    Dim indx As Integer = CheckedListBox1.FindString(TextBox1.Text)
    If indx >= 0 Then CheckedListBox1.SelectedIndex = indx
End Sub

Open in new window

0
 
Alexandre SimõesManager / Technology SpecialistCommented:
Grab the Keydown event of the textbox to apply the selection on the checkedlistbox.
0
 
leeds2000Author Commented:
hmm, do you have a suggestion to a code here?
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
leeds2000Author Commented:
yes, of the good reason i cant get any answer, just crap like this, so real experts dont enter the question and helps out. These so called experts giving answers that dont work, becouse they dont test it. This does not help the question askers, and makes us double post.

So yes i did double post, but please DONT ANSWER IF YOU DONT KNOW!!! this just screws up everything.

I will get the other post deleted..
0
 
ZeonFlashCommented:
Given the parameters that you stated in your question, I set up a test application with a textbox and a checked listbox.  The 'working' solution that I came up with only needed the TextChanged event of the textbox to accomplish what you wanted:  type in a textbox and have it automatically select the first item that matched the text.  It works in my application, but you may have some other scenario that is causing it NOT to work.  That's why we try to have a dialog on here...to figure out why it's not working for you.  I'm afraid "real experts" can't answer questions if we don't know all of the problems.  We're also busy people, so you can't expect an answer instantly after every post.

Now if you'd like to continue diagnosing the problem, let's do that.  But don't abandon a question when the first response doesn't seem to work like you expected.
0
 
leeds2000Author Commented:
Ok, sorry, im just frustrated here, ive been sitting here with this problem for hours so my brain is annoyed, no hard feelings, sorry again :)

Thanks for trying to help, again to the problem

I have a checkedlistbox getting data from a sql database

I have a textbox which i want to "search" through the checked listbox. Example writing "f" and there is only one name that starts with "f" like "frank" i want this checklistbox to automatically jump down to the frank name.

I tried the checkedlistbox1.text = textbox1.text but this code needed me to write the WHOLE name before it jumped down to frank, so i needed to write "frank" before it found a match and jumped down to "frank"

I need the checkedlistbox to find a match as soon as i press the button "f" and so on. Hope you understand my problem

and no hard feelings :)
0
 
ZeonFlashCommented:
The reason that "checkedlistbox1.text = textbox1.text" isn't working is because it only searches by item, meaning that it won't attempt to make partial matches (like "fr" in "frank").

Just to make sure, what is the value of the SelectionMode for the CheckedListBox?

Also, how are you binding the data (and setting the Display and Value Members) to the CheckedListBox?  
0
 
leeds2000Author Commented:
Im a noob at VB just to have it cleared :)

"Just to make sure, what is the value of the SelectionMode for the CheckedListBox?"

hmmm im not sure, but i could add a Me.checkedlistbox1.selectedindex = -1 at form load, if this is what you mean? il try this :)


"Also, how are you binding the data (and setting the Display and Value Members) to the CheckedListBox?"

This is the part i get the data from the sql database right? :)

        Dim drv As DataRow
        Dim customerrows As DataRowCollection = DsCustomer.CUSTOMER.Rows
        For Each drv In customerrows
            Me.checklistbox.Items.Add(drv(2).ToString() + " " + drv(1).ToString() + " " + drv(3).ToString())
        Next


if there is anything else, please ask and il try giving the information as best as I can :)
Dim drv As DataRow
        Dim customerrows As DataRowCollection = DsCustomer.CUSTOMER.Rows
        For Each drv In customerrows
            Me.checklistbox.Items.Add(drv(2).ToString() + " " + drv(1).ToString() + " " + drv(3).ToString())
        Next

Open in new window

0
 
leeds2000Author Commented:
Ive figured it out

easy code, just used this:


Private Sub Text1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Text1.TextChanged

Dim i As Integer = checkedListbox1.FindString(Textbox1.Text)

checkedlistbox1.SelectedIndex = i

End Sub


Thanks for the try atleast
0
 
leeds2000Author Commented:
Hmm, well i didnt manage to get that code you wrote to work, but if you repost with the code i wrote i can give you the points :)

It may be the last line of the code

If indx >= 0 Then CheckedListBox1.SelectedIndex = indx

that doesnt make it work, i dont know why, but hey, im a noob so i dont know why it doesnt :/

But the code i wrote works atleast for my part, but if you can repost the code il grant the points :)
0
 
ZeonFlashCommented:
Not sure why it doesn't work when you include the "indx >= 0" check.  The FindString method returns a -1 if nothing could be found, so it was merely a check to make sure that an item was getting selected.  Otherwise, if you typed in "fr" it would go to "Frank", but if you typed "frb", it would just select the first item in the listbox.  Weird stuff.
0
 
leeds2000Author Commented:
As you have been very helpful i need to give you this points, thanks for the help, and i will probably ask some more about VB in the future :)

Though it worked (almost) it was as close as you can get, so a good answer :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.