Building listbox from datareader (need valuemember)

12-08-2004, 03:10 PM
The deal is -- I need to build a listbox using a data reader with both a displaymember and a valuemember.

There are three ways I know to build a listbox (there are probably more, but these are the three I've tried):
1. data adapter
2. "list assigner" -- array setup
3. data reader

#1/#2 work fine -- but both methods select listbox.item(0) after creation. I have tried setting the selection to -1 -- which works -- but the way I am using listboxes, it is not effective. #3 (data reader) -- has no default selection -- which is exactly what I want.

My usage:
I have listbox1 which I populate from the database. Listbox 2 is also populated from the db -- dependent on the selection in listbox1 for the parameter. My display data is created based on the listbox2 selection.

What happens:
When I change the selection in listbox1 -- listbox2 is refreshed with new data. When listbox2 refreshes -- the build forces the index to item(0) (and the display reflects this) -- then I force the selection to -1 (to remove the highlight) -- and the displayed data disappears(as it should) -- and everything is fine again.

I need to eliminate that temporary data flash between when the selection is 0 (by default) and when I set it to -1....

I know there are workarounds -- visibility/remove-add/etc... but I shouldn't have to do a bunch of extra code everywhere -- I just want to build the listbox and not have it select the first item by default. The only way I have been able to do this is through the data reader -- but then I can't get the display/value members to work correctly.

Sorry for the wordiness -- in short, I need to build a listbox using datareader and having datamember and valuemember ability -- has anyone accomplished this?


EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum