Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete Bindings

Status
Not open for further replies.

BobBob10

Programmer
Apr 24, 2005
57
GB
How do I delete the bindings from a list box. My code fails at:

Code:
 Dim i As Integer = objAddTo.Items.Count
        Dim SortListA As ArrayList
        Dim j As Integer

        Do While i > 0
            If objAddTo.Items.Item(i - 1).Selected = True Then
                Me.objRemoveFrom.Items.Add(Me.objAddTo.Items.Item(i - 1))
                objAddTo.Items.Remove(objAddTo.Items.Item(i - 1))
                'Sort list boxes
                SortListA = New ArrayList
                'Me.objRemoveFrom.DataSource = SortListA
                For j = 0 To objRemoveFrom.Items.Count - 1
                    SortListA.Add(objRemoveFrom.Items(j).Value)
                Next 'j
                objRemoveFrom.DataSource = SortListA
'Fails here 
                objRemoveFrom.DataBind()
                Session("SortA") = SortListA
                Session("SortA").sort()
            End If
            i -= 1
        Loop

my code fails as the list box is already binded.

How do I clear this to create a new binding so that my list box will sort?
 
What error do you get?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Would you like to explain how in case any future readers come across the same problem (it also means you are giving something back to Tek-Tips)?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
OK:

Code:
        Dim i As Integer = objAddTo.Items.Count
        Dim SortListA As ArrayList
        Dim j As Integer
        Dim k As Integer

        Do While i > 0
            If objAddTo.Items.Item(i - 1).Selected = True Then
                Me.objRemoveFrom.Items.Add(Me.objAddTo.Items.Item(i - 1))
                objAddTo.Items.Remove(objAddTo.Items.Item(i - 1))
                'Sort list boxes
                SortListA = New ArrayList
                For j = 0 To objRemoveFrom.Items.Count - 1
                    SortListA.Add(objRemoveFrom.Items(j).Value)
                Next 'j
                SortListA.Sort()
                objRemoveFrom.Items.Clear()
                For k = 0 To SortListA.Count - 1
                    Me.objRemoveFrom.Items.Add(SortListA.Item(k))
                Next 'k
            End If
            i -= 1
        Loop


I basically created an Array and sorted that array. Cleared the list box and populated with new Array.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top