Solved

Search a checkedlistbox using a textbox

Posted on 2007-11-16
14
449 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
 
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now