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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listbox bound to dataview shows blank item??? 1

Status
Not open for further replies.

SJG0526

Programmer
Jul 5, 2002
108
US
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?

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
 
When you call AddNew on a DataView (drv = dvSelectionOutput.AddNew()), after you add information to the fields, to commit the changes to the DataView you have to either move to another record or call the DataRowView's EndEdit method. So you need something like this:

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)
[red]drv.EndEdit()[/red]
Next

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day! Ye has a choice: talk like a pira
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top