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:
'Arealist code Private Sub AreaList_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AreaList.SelectedIndexChanged ProcessGrid.DataMember = AreaList.GetItemText(AreaList.SelectedItem) Dim selectedIndex As Integer = AreaList.SelectedIndex ListUp.Enabled = selectedIndex <> -1 AndAlso selectedIndex > 0 ListDown.Enabled = selectedIndex <> -1 AndAlso selectedIndex < AreaList.Items.Count - 1 End Sub Private Sub MoveSelectedItem(ByVal increment As Integer) Dim selectedIndex As Integer = AreaList.SelectedItem + increment Dim selectedItem As Object = AreaList.SelectedItem AreaList.Items.Remove(selectedItem) AreaList.Items.Insert(selectedIndex, selectedItem) AreaList.SelectedIndex = selectedIndex End Sub Private Sub ListDown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListDown.Click MoveSelectedItem(1) End Sub Private Sub ListUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListUp.Click MoveSelectedItem(-1) End Sub




Reply With Quote