473,804 Members | 3,038 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

'Autocompleting ' Listbox?

CJM
I would like to be able to use an autocompleting listbox - that is, one
where you can select an item in the list by typing the first few characters;
the standard IE listbox only responds to the first character.

I'm happy to pay a few quid for a 3rd-party component/activex control if
necessary but I imagine something equally good could be done with
client-side code...

Any suggestions?

Note: This is for an intranet-based ASP application, where all clients are
using IE6.

Chris

--
cj*******@REMOV EMEyahoo.co.uk
[remove the obvious bits]
Jul 22 '05 #1
3 1894
CJM wrote:
I would like to be able to use an autocompleting listbox - that is,
one where you can select an item in the list by typing the first few
characters; the standard IE listbox only responds to the first
character.
I'm happy to pay a few quid for a 3rd-party component/activex control
if necessary but I imagine something equally good could be done with
client-side code...

Any suggestions?

Note: This is for an intranet-based ASP application, where all
clients are using IE6.


See if you can adapt the dynamic listbox demo I wrote which is posted here:
http://www.thrasherwebdesign.com/ind...asp&c=&a=clear

Bob Barrows

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 22 '05 #2
"CJM" <cj*******@news group.nospam> wrote in message
news:#B******** ******@TK2MSFTN GP09.phx.gbl...
I would like to be able to use an autocompleting listbox - that is, one
where you can select an item in the list by typing the first few characters; the standard IE listbox only responds to the first character.

I'm happy to pay a few quid for a 3rd-party component/activex control if
necessary but I imagine something equally good could be done with
client-side code...

Any suggestions?

Note: This is for an intranet-based ASP application, where all clients are
using IE6.

Chris

--
cj*******@REMOV EMEyahoo.co.uk
[remove the obvious bits]

For an IE-only solution, check out:

// Cooking with JavaScript & DHTML
// Bonus Recipe: Typing select Element Choices in IE for Windows
// http://www.oreillynet.com/pub/a/java...nygoodman.html
// http://www.oreillynet.com/lpt/a/4135
Jul 22 '05 #3
CJM
Thanks Guys...

I actually found a script which works in virtually the same way as the
O'Reilly one, using javascript on the clientside rather than Bob's XML Data
Island solution.

I'm not sure which is the better approach, but I can guarantee the
javascript is enabled in my target browsers, so I've gone for that option.
I'm saving a few server roundtrips with no drawbacks that I can see...

My code snippet is below. In a similar vein to the O'Reilly solution, I'm
calling this procedure via the OnKeyPress event handler

Chris

Snippet:
var toFind = ""; // Variable that acts as keyboard buffer
var timeoutID = ""; // Process id for timer (used when stopping
// the timeout)
timeoutInterval = 250; // Milliseconds. Shorten to cause keyboard
// buffer to be cleared faster
var timeoutCtr = 0; // Initialization of timer count down
var timeoutCtrLimit = 3 ; // Number of times to allow timer to count
// down
var oControl = ""; // Maintains a global reference to the
// control that the user is working with.

function listbox_onkeypr ess(){

// This function is called when the user presses a key while focus is in
// the listbox. It maintains the keyboard buffer.
// Each time the user presses a key, the timer is restarted.
// First, stop the previous timer; this function will restart it.
window.clearInt erval(timeoutID )

// Which control raised the event? We'll need to know which control to
// set the selection in.
oControl = window.event.sr cElement;

var keycode = window.event.ke yCode;
if(keycode >= 32 ){
// What character did the user type?
var c = String.fromChar Code(keycode);
c = c.toUpperCase() ;
// Convert it to uppercase so that comparisons don't fail
toFind += c ; // Add to the keyboard buffer
find(); // Search the listbox
timeoutID = window.setInter val("idle()", timeoutInterval );
// Restart the timer
}
}

function listbox_onblur( ){
// This function is called when the user leaves the listbox.

window.clearInt erval(timeoutID );
resetToFind();
}

function idle(){
// This function is called if the timeout expires. If this is the
// third (by default) time that the idle function has been called,
// it stops the timer and clears the keyboard buffer

timeoutCtr += 1
if(timeoutCtr > timeoutCtrLimit ){
resetToFind();
timeoutCtr = 0;
window.clearInt erval(timeoutID );
}
}

function resetToFind(){
toFind = ""
}
function find(){
// Walk through the select list looking for a match

var allOptions = document.all.it em(oControl.id) ;

for (i=0; i < allOptions.leng th; i++){
// Gets the next item from the listbox
nextOptionText = allOptions(i).t ext.toUpperCase ();

// By default, the values in the listbox and as entered by the
// user are strings. This causes a string comparison to be made,
// which is not correct for numbers (1 < 11 < 2).
// The following lines coerce numbers into an (internal) number
// format so that the subsequent comparison is done as a
// number (1 < 2 < 11).

if(!isNaN(nextO ptionText) && !isNaN(toFind) ){
nextOptionText *= 1; // coerce into number
toFind *= 1;
}

// Does the next item match exactly what the user typed?
if(toFind == nextOptionText) {
// OK, we can stop at this option. Set focus here
oControl.select edIndex = i;
window.event.re turnValue = false;
break;
}

// If the string does not match exactly, find which two entries
// it should be between.
if(i < allOptions.leng th-1){

// If we are not yet at the last listbox item, see if the
// search string comes between the current entry and the next
// one. If so, place the selection there.

lookAheadOption Text = allOptions(i+1) .text.toUpperCa se() ;
if( (toFind > nextOptionText) &&
(toFind < lookAheadOption Text) ){
oControl.select edIndex = i+1;
window.event.ca ncelBubble = true;
window.event.re turnValue = false;
break;
} // if
} // if

else{

// If we are at the end of the entries and the search string
// is still higher than the entries, select the last entry

if(toFind > nextOptionText) {
oControl.select edIndex = allOptions.leng th-1 // stick it
// at the end
window.event.ca ncelBubble = true;
window.event.re turnValue = false;
break;
} // if
} // else
} // for
} // function
Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
3136
by: amber | last post by:
Hello. Can someone tell me what I may be doing wrong here? I'm using the code (lboxRP is a listbox): Dim newRPindex As Integer newRPindex = Me.lboxRP.FindString(RP) Me.lboxRP.SetSelected(newRPindex, True) When the last line executes, I get an error message:
9
7029
by: Megan | last post by:
Hi- I'm creating a database of music bands with their cds and songs. I'm trying to program an SQL statement so that I can enter a string of text in a textbox, press the 'Enter' key, and have it return the associated records to a listbox. Once the listbox has the records, I want to select a record, which will open a form associated with the selected record in the listbox.
3
3615
by: Paul T. Rong | last post by:
I have a listbox (of product names) control on my form. I want to pass the selected item (a product name) to a subform, and the product unitprice should apear automatically next to the product name in the subform. Is it possible? How do I do this? Thanks in advance. Paul from Slovakia
8
2886
by: Oddball | last post by:
Ok - I have a ListBox control and I'm ready to write my own DrawItem event handler. What I want to draw as the item is another control. I have created a user control that I would like to list in this listbox but I can't for the life of me figure out how to draw the control inside ListBox... I get as far as: private void lbImageList_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
6
2884
by: Chris Leuty | last post by:
I am populating a multiselect Listbox from a dataset, with the content of the listbox filled by one table, and the selections determined from another table. So far, I have been keeping the dataset a denormalized mirror of the database, but I'm not having much luck getting the selection logic down (I haven't found a 'hook' where I can access the listbox object as an object to set the listitem's selected property before it gets rendered).. ...
7
4540
by: Dave | last post by:
Hi all, After unsuccessfully trying to make my own dual listbox control out of arraylists, I decided to look for a 3rd party control. I've looked for over a week now and can't find anything but ASP.Net stuff when I need a Windows Form control. I've seen dual listbox populators in countless Windows applications, and have seen them run very fast, so I figured this would be extremely popular. Here's how it should work:
3
2301
by: Ali Chambers | last post by:
Hi, I have created a listbox called "dtlist1" on my VB.NET form. I call a procedure as follows: Private Sub openfile(flname As String) dtlist1.Items.Clear() etc..
1
4033
by: Sunray | last post by:
I have a form called the sales form and i have 2 sets of listboxes So what happens is. i add items form the bottom set of list boxes which are bound to a data base to the top set of list boxes which are not bound, I select from the bottom set and add to the top set which works fine, but now i decide to remove an item from the top set. when i tried to use a remove item code it worked fine, it did delete the item form the list but it added...
5
2857
by: Academia | last post by:
(If you've seen this in the drawing NG, sorry. I inadvertently sent it there.) I have a listbox populated with Objects. The Class has a String field that ToString returns. I assume that is what the ListBox uses for its display. Correct?
0
9579
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10571
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10326
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7615
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6851
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5520
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4295
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2990
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.