Populating comboboxes and listboxes

keb1965

Well-known member
Joined
Feb 9, 2009
Messages
103
Programming Experience
10+
I have been tasked with redeveloping a desktop application as a web application and many of the classes used in the desktop application are pretty complex. That being said, I'd like to keep from having to completely rewrite everything from scratch .. I know .. what in the world am I thinking ...

Anyway, in the desktop application users create items that end up populating comboboxes and listboxes in dozens of places where the objects being populated are custom classes that fulfil specific needs within the company, in fact in some listboxes, different classes of objects are populated. Now we are moving to a web based application and what once worked will not. For example, we could populate a listbox like so:

    Me.ListBox1.Items.Add(New customerObject(Name, AccountNumber, Address, Type))
    Me.ListBox1.Items.Add(New vendorObject(Name, AccountNumber, Address, Type))


To make this work like we wanted, all we needed to do was override the ToString method of each class:

    Public Overrides Function ToString() As String
        Return String.Format("{0} --> {1}", _acctNo, _name)
    End Function


Keep in mind the code above is abbreviated for clarity and the classes are much more complex than would be apparent from this code.

Now that we are moving to a web based application, simply adding an object to a ListBox or ComboBox (DropDownList) isn't possible, or at least I don't know how to do it, else I wouldn't be here asking for help. ;-)

I have tenatively added a method to each class "ToListBoxItem" that returns a new listboxitem that can be accepted as an item for population, however, because objects are not persistent server-side, all of the internal properties are lost ... and the missing items are not sent to the client.

So .....

I am wanting to keep the traffic to a minimum (there is way too much data already) and I don't want to have to keep repopulating the listbox or combobox over and over again with all new data .. it gets really expensive in traffic and can slow the application considerably. Once the data is in the listbox, it is only going to be used for selection purposes and will not be saved back to the server, but because the data is subject to be edited client-side, I need to be able to access all of it in a simple and efficient manner. So, what should I be doing here .. perhaps just deal with the traffic overhead and simply bind a datatable to the control? At least then I would have a copy of the data client-side, even if I have to resend all of it on postbacks. The only problem is that the data is generated both server-side and client-side so the entire data structure would have to make the roundtrip each postback.
 
Back
Top