Connecting Tech Pros Worldwide Forums | Help | Site Map

Using values in non-databound listboxes

Scott McNair
Guest
 
Posts: n/a
#1: Feb 5 '08
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
will do.

Cor Ligthert[MVP]
Guest
 
Posts: n/a
#2: Feb 6 '08

re: Using values in non-databound listboxes


Scott,

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

Cor
Jack Jackson
Guest
 
Posts: n/a
#3: Feb 6 '08

re: Using values in non-databound listboxes


On Tue, 05 Feb 2008 13:50:49 -0800, Scott McNair
<smcnair@beachexpress.takethispartout.comwrote:
Quote:
>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).
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]
Guest
 
Posts: n/a
#4: Feb 7 '08

re: Using values in non-databound listboxes


Jack,

Be aware that with 2 datatables you don't benefit of the binding.
However this can be because of the question an alternative for the OP

Cor
Closed Thread