I am in the Try It Out that begins on page 129. When I try to complete step 5, my code looks like this:
Private Sub LoadListBox()
Dim PersonListAdapter As New _PO_DataDataSetTableAdapters.PersonTableAdapter
Dim PersonListTable As New _PO_DataDataSet.PersonDataTable
PersonListAdapter.Fill(PersonListTable)
With lstPersons
.Items.Clear()
.DisplayMember = "DisplayName"
For Each CurrentRow As _PO_DataDataSet.PersonRow In PersonListTable.Rows
Dim CurrentPerson As New Person(CurrentRow.NameFirst, CurrentRow.NameLast)
CurrentPerson.ID = CurrentRow.ID
.Items.Add(CurrentPerson)
Next
End With
End Sub
I am a little unsure, but I believe that is exactly what the book instructs me to do. When I try to run the program, clicking the "Show List" button produces the lstPersons panel, but it is empty, and then
VB errors out with this message:
"Items collection cannot be modified when the DataSource property is set."
The offending line of code is ".Items.Clear()", but even when I delete that line, I get the same error message for ".Items.Add(CurrentPerson)". It seems like declaring PersonListAdapter and PersonListTable in the same subroutine is causing this problem, but from the book, I don't know where that bit of code goes.
Please help!!!