Groups | Blog | Home
all groups > vb.net > february 2008 >

vb.net : Using values in non-databound listboxes


Scott McNair
2/5/2008 1:50:49 PM
Hi,

I have two listboxes (we'll call them LB1 and LB2). LB1 and LB2 are both
populated from data, with the valuemember bound to the ID, and the
displaymember bound to the data's text.

I would like to be able to move the items back and forth between LB1 and
LB2 by using "<-" and "->" buttons, so databinding is ruled out (since you
can't add or remove items to a bound listbox).

My alternative is to populate LB1 manually, by iterating through the
datarows and adding an item for each row. The problem with this is that I
lose the ability to tie an ID to the valuemember (since a non-databound
listbox is indexed [0,1,2,...] rather than value-bound).

Does anybody have a suggestion as to how I can go about achieving this?
I'm not married to the listbox at this point, and any comparable control
Jack Jackson
2/5/2008 9:36:02 PM
On Tue, 05 Feb 2008 13:50:49 -0800, Scott McNair
[quoted text, click to view]

But you can add and remove to/from the underlying data source.

I think I might use two BindingList(Of T), one for each listbox. Add
the appropriate records to each. You would probably need to
implements sorting in the BindingLists.

You could also use two DataTables instead.
Cor Ligthert[MVP]
2/6/2008 6:32:16 AM
Scott,

Why can you not use a dataview with a rowfilter to solve your problem.

AddThis Social Bookmark Button