logo
vbRad Home
Source Code
Book Reviews
Forum
Links
About Us
Contribute

Compare Databases with SQL Effects Clarity
 
 ServerSide HTML ListBox Component

Posted on
6/7/2001
Author:
Robert Gelb
Email:
Not Shown
Applies To OS:
NT, 9x, 2000
Product:
5, 6



Download the source code (3.25 kb) for this article

For those of us who completely ditched ASP in favor of compiled VB COM objects (see article), life has been made a lot less aggravating. One side effect of the move away from ASP is the need to generate various listboxes (the <select>...</select> variety) in code. Since most listboxes are pretty much the same, it stands to reason that a reusable class is needed that generates HTML listboxes quickly and easily. It further stands to reason that since we all know and love the way the standard listbox works, why not emulate that interface.

So that's what this class does: it emulates the standard listbox interface, while adding its HTML-specific methods and properties and improving on existing methods. Here is what's changed from the standard interface:

HtmlList = object.Render
Returns the generated HTML list. It is this easy.

object.AddItem Item as Variant, Optional Index as Long, Optional ItemData as Variant
As you can see, I've added ItemData parameter as optional, so that you can set a line in one shot. Also, both Item and ItemData are now Variants so if you are adding data from the register you no longer have to check whether it is NULL or not.

index = object.SearchItem Item as Variant
index = object.SearchItemData ItemData as Variant
I've added search routines looping through the list or reaching for that ubiquotous SendMessage API. This routine returns an index of the found item or -1 if nothing found. You can use it like this: oList.ListIndex = oList.SearchItem("Some Item")

Among other changes are properties like Name, Size, RenderMethod and Style that basically define the look of the listbox. RenderMethod is important because it defines whether the ListBox will have SELECT headers around the data or not.

Check out the attached sample linked at the top of this page. Some of iteration of this handy class include methods where you can assign it a Recordset and have it spit out a populated list. I didn't include it here because this functionality is particular to my needs - yours maybe different. This class has saved me countless hours. I hope it does the same for you.





Add Your Comment  

Name: Email Address: all fields optional
Notify me via email when someone responds to this message (valid email required).

Enter the word:
 



Comments
#1. By vzcxvzcv. Posted on 7/11/2006 1:51:21 PM
zvzxc

#2. By 8p89p89. Posted on 11/29/2006 4:18:49 AM
0p890py89p8

#3. By dsfg. Posted on 12/18/2006 3:23:47 PM
sdf

#4. By fdsaf. Posted on 1/28/2008 6:11:06 PM
fsdaf
fdafdasf
fdsafdsf