Moving items in databound ListBox?

I have worked out how to move items in ListBox, but it doesn't seems to work when the ListBox is bound to a DataSource. 

How can i move items when ListBox is populated using DataSource property  


Answer this question

Moving items in databound ListBox?

  • JeffreyS

    well i can delete the current row using Delete method, but how can i add it back to list at different index.

    for eg if the user has selected the first item in the list and press down button, it should delete the row at index 0 and insert it back into the list at index 1.

  • NickC999

    Yea, my bad

    You will have to do it via the currencymanager's List property (insert) or rebind the listbox.

    Dim CM as currencymanager = ctype(me.bindingcontext(listbox.datasource),currencymanager)

    'dr is new datarow
    cm.list.insert(0,dr)

  • damned

    well i tried that, but the inserted row is not showen in the ListBox
  • donovanf

    datatable.rows.insertat(index,datarow)
  • ryanlifferth

    Maybe the better question is, why do you want to move items

    I had a app I have been working on where I had one list box with column names and another on the right hand side and inbetween the two I had arrows (one pointing left, one pointing right) and the user would select a column and hit the arrow and it would move the column to the right list box.

    Now for the right list box I just redid a new DataRow then set the column name and added it to the datasource of the right hand listbox. 

    For the left hand listbox I had the datasource set to a DataView and I just filtered out the column.
    DV.rowfilter = "ColumnName <> 'mychossenColumn'" 
    I would keep adding to the filter for each column I moved.
    I would delete from the filter for each column I put back to the lefthand listbox.

    Hope this helps. Sometimes is good to explain what you are wanting to happen so that others can provide different ways of doing the goal. After all there is always more then one way to skin a cat.

  • HiralJB

    dim CM as currencymanager = ctype(me.bindingcontext(listbox1.datasource),currencymanager)

    for x as int16 to cm.count -1
    cm.position = x
    Dim DRV as datarowview = ctype(cm.current,datarowview)

    if drv.item("ColumnName") = "" then 'a way to check the a column
    drv.delete()
    end if

    next

    Hope this helps

  • MVP User120890

    no good mate :(

    Its says cannot insert external objects to the list


  • Moving items in databound ListBox?