A
Angel Blue01
I have a form with a binding navigator that draws from a database via
drag-and-drop-created controls. I'm filling a listbox with the results
of a query. The listbox contains data related to the record that the
user is viewing but cannot be databound because other events and user
input are needed when the user selects an item from the listbox.
Each time the user clicks the binding navigator to move to the next
record I have this:
<code>
Private Sub VolunteersBindingSource_PositionChanged(ByVal sender As
Object, ByVal e As System.EventArgs) Handles
VolunteersBindingSource.PositionChanged
lboCurrentActivities.Items.Clear()
Call lboCurrentActivities.Refresh()
Dim cnnVol As OleDbConnection
'Dim cmdLineItemSelect As OleDbCommand
'get the activities for that volunteer in the listbox
Try
cnnVol = New OleDbConnection(strconn)
cnnVol.Open()
Dim strSQL As String = "SELECT lineitems.activitycode,
activitydescription, lineitems.newrenew, lineitems.batchnumber FROM
lineitems INNER JOIN activities on lineitems.activitycode =
activities.activitycode WHERE [vol#]=" &
VolunteersBindingSource.Position + 1 & ""
Dim testda = New OleDbDataAdapter(strSQL, cnnVol)
testda.Fill(testds, "li")
Dim testdt As New DataTable
testdt = testds.Tables(0)
Dim testdr As DataRow
If lboCurrentActivities.Items.Count = 0 Then
For Each testdr In testdt.Rows
lboCurrentActivities.Items.Add(testdr("activitydescription"))
Next
End If
' the newrenew textbox will be filled on listbox selction changed
based on the dataset
Catch ex As Exception
MessageBox.Show(ex, "Position changed")
End Try
End Sub
</code>
The listbox is supposed to clear each time the record advances but it
does not. The previous items stay in the listbox. The program insists
there are no items in the listbox and fills it with the new items
although the user can select and item from the supposedly cleared
items.
How do I get this listbox to clear?
drag-and-drop-created controls. I'm filling a listbox with the results
of a query. The listbox contains data related to the record that the
user is viewing but cannot be databound because other events and user
input are needed when the user selects an item from the listbox.
Each time the user clicks the binding navigator to move to the next
record I have this:
<code>
Private Sub VolunteersBindingSource_PositionChanged(ByVal sender As
Object, ByVal e As System.EventArgs) Handles
VolunteersBindingSource.PositionChanged
lboCurrentActivities.Items.Clear()
Call lboCurrentActivities.Refresh()
Dim cnnVol As OleDbConnection
'Dim cmdLineItemSelect As OleDbCommand
'get the activities for that volunteer in the listbox
Try
cnnVol = New OleDbConnection(strconn)
cnnVol.Open()
Dim strSQL As String = "SELECT lineitems.activitycode,
activitydescription, lineitems.newrenew, lineitems.batchnumber FROM
lineitems INNER JOIN activities on lineitems.activitycode =
activities.activitycode WHERE [vol#]=" &
VolunteersBindingSource.Position + 1 & ""
Dim testda = New OleDbDataAdapter(strSQL, cnnVol)
testda.Fill(testds, "li")
Dim testdt As New DataTable
testdt = testds.Tables(0)
Dim testdr As DataRow
If lboCurrentActivities.Items.Count = 0 Then
For Each testdr In testdt.Rows
lboCurrentActivities.Items.Add(testdr("activitydescription"))
Next
End If
' the newrenew textbox will be filled on listbox selction changed
based on the dataset
Catch ex As Exception
MessageBox.Show(ex, "Position changed")
End Try
End Sub
</code>
The listbox is supposed to clear each time the record advances but it
does not. The previous items stay in the listbox. The program insists
there are no items in the listbox and fills it with the new items
although the user can select and item from the supposedly cleared
items.
How do I get this listbox to clear?