I'm trying to add a new record to a listbox. The listbox is bound to a dataview. When I trace through the code below, the dataview gets the newly added record correctly and the listbox says it has all the items. Problem is, the listbox shows a blank item where the newly added item should be. If I add another item, the listbox shows me the previously added item correctly but the newest item added is blank.
Seems like some kind of refresh problem?
Can anyone help me?
Seems like some kind of refresh problem?
Can anyone help me?
Code:
Private Sub btnRight_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRight.Click
Dim x As Integer
Dim drv As DataRowView
'-- Add selected available fields to chosen fields list
With Me.lstOutputFieldsAvailable
For x = 0 To .SelectedItems.Count - 1
'add to chosen fields datatable
drv = dvSelectionOutput.AddNew()
drv("OrderNo") = giOrderNo
drv("SelectionOutputNo") = Me.dvSelectionOutput.Count
drv("FieldName") = Me.lstOutputFieldsAvailable.SelectedItems.Item(x)
Next
'take out of available fields
Dim ct As Integer = .SelectedItems.Count - 1
For x = 0 To ct
.Items.Remove(.SelectedItems.Item(0))
Next
End With
Me.lstOutputFieldsChosen.SelectedIndex = Me.lstOutputFieldsChosen.Items.Count - 1
mbDataChanged = True
End Sub