I have a listbox that must be bound to a datatable. This morning I attempted to write some code that would allow the user to move a listbox item up or down in the list, and to disable the sort buttons if the item is on top or bottom. When I ran the applicaiton, I recieved an error stating that I cannot do this while the listbox is bound to a datasource. Basically I assumed that the listbox works the same as a datagridview in that manipulating the listbox also manipulates the datatable. This is not the case. I must have the listbox bound to a dattable because later I need it to export to xml. So my question is this, I need to change the index of a datatable row. Basically it is a datatable with two columns, an index and a string.

thx

Juri


ps... here is the code I use for sorting.....


VB Code:
  1. 'Arealist code
  2.  
  3.     Private Sub AreaList_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AreaList.SelectedIndexChanged
  4.         ProcessGrid.DataMember = AreaList.GetItemText(AreaList.SelectedItem)
  5.         Dim selectedIndex As Integer = AreaList.SelectedIndex
  6.         ListUp.Enabled = selectedIndex <> -1 AndAlso selectedIndex > 0
  7.         ListDown.Enabled = selectedIndex <> -1 AndAlso selectedIndex < AreaList.Items.Count - 1
  8.     End Sub
  9.  
  10.     Private Sub MoveSelectedItem(ByVal increment As Integer)
  11.         Dim selectedIndex As Integer = AreaList.SelectedItem + increment
  12.         Dim selectedItem As Object = AreaList.SelectedItem
  13.  
  14.         AreaList.Items.Remove(selectedItem)
  15.         AreaList.Items.Insert(selectedIndex, selectedItem)
  16.         AreaList.SelectedIndex = selectedIndex
  17.     End Sub
  18.  
  19.     Private Sub ListDown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListDown.Click
  20.         MoveSelectedItem(1)
  21.     End Sub
  22.  
  23.     Private Sub ListUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListUp.Click
  24.         MoveSelectedItem(-1)
  25.     End Sub