Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Search a checkedlistbox using a textbox

Posted on 2007-11-16
14
496 Views
Last Modified: 2011-10-03
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
0
Comment
Question by:leeds2000
  • 7
  • 5
14 Comments
 
LVL 30

Expert Comment

by:Alexandre Simões
ID: 20300823
Grab the Keydown event of the textbox to apply the selection on the checkedlistbox.
0
 
LVL 3

Author Comment

by:leeds2000
ID: 20300838
hmm, do you have a suggestion to a code here?
0
 
LVL 17

Expert Comment

by:ZeonFlash
ID: 20301018
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 3

Author Comment

by:leeds2000
ID: 20301068
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
 
LVL 17

Expert Comment

by:ZeonFlash
ID: 20301188
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
 
LVL 3

Author Comment

by:leeds2000
ID: 20301235
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
 
LVL 17

Expert Comment

by:ZeonFlash
ID: 20301352
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
 
LVL 3

Author Comment

by:leeds2000
ID: 20301416
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
 
LVL 3

Author Comment

by:leeds2000
ID: 20303512
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
 
LVL 17

Accepted Solution

by:
ZeonFlash earned 500 total points
ID: 20304818
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
 
LVL 3

Author Comment

by:leeds2000
ID: 20308070
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
 
LVL 17

Expert Comment

by:ZeonFlash
ID: 20308585
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
 
LVL 3

Author Closing Comment

by:leeds2000
ID: 31409626
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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question