Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / February 2007

Tip: Looking for answers? Try searching our database.

(VB.NET 1.1) Windows Forms Listbox help

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Philip - 06 Feb 2007 15:31 GMT
Hi,

I have a listbox with 3000 entries, all of 4 chars, and the user needs to be
able easily select dozens of them...

When the user is selecting items, they type for example ABB, and the listbox
first goes to A, then B, rather than searching for ABB.

Is there any way to setup the listbox so that the user can type for example
ABB and it will jump to ABB instead of going to AAAA, then BBBB

in other words I need the listbox to take up to 4 keystrokes and search for
the nearsest match in the list...

is there any way to do that - or is there a sample I can look at eanywhere?

thanks

Philip
ClayB - 06 Feb 2007 18:04 GMT
You can try handling the KeyPress event and searching for the item
there.

private string match = "";
private int location = -1;

void listBox1_KeyPress(object sender, KeyPressEventArgs e)
{
   if (e.KeyChar == '\b')
   {
       location = -1;
       match = "";
       this.listBox1.SelectedIndex = 0;
   }
   else if (char.IsLetter(e.KeyChar))
   {
       match += e.KeyChar;
       int i = this.listBox1.FindStringExact(match);
       if (i > -1)
       {
           this.listBox1.SelectedIndex = i;
       }
       else if (location < this.listBox1.Items.Count - 1)
       {
           i = this.listBox1.FindString(match, location + 1);
           if (i > -1)
           {
               location = i;
               this.listBox1.SelectedItem = this.listBox1.Items[i];
           }
       }
       else
       {
           location = -1;
           match = "";
           this.listBox1.SelectedIndex = 0;
       }
   }
   e.Handled = true;
}

=====================
Clay Burch
Syncfusion, Inc.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.