473,381 Members | 1,497 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,381 software developers and data experts.

Listbox not clearing

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("activitydes cription"))

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?

Aug 14 '07 #1
3 1981
Angel,

I think the datatable's Fill method is adding rows to the "li" table.

Then the For Each loop is adding back the old data to the listbox, along
with the new data.

Kerry Moorman
"Angel Blue01" wrote:
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("activitydes cription"))

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?

Aug 14 '07 #2
On Aug 14, 1:02 pm, Kerry Moorman
<KerryMoor...@discussions.microsoft.comwrote:
Angel,

I think the datatable's Fill method is adding rows to the "li" table.

Then the For Each loop is adding back the old data to the listbox, along
with the new data.
OK, then how do I delete that old data so it doesn't add it back?
Aug 15 '07 #3
Angel,

Maybe before calling the dataadapter's Fill method you could clear the table:

If testds.Tables.Count 0 Then
testds.Tables(0).Clear()
End If

Kerry Moorman
"Angel Blue01" wrote:
On Aug 14, 1:02 pm, Kerry Moorman
<KerryMoor...@discussions.microsoft.comwrote:
Angel,

I think the datatable's Fill method is adding rows to the "li" table.

Then the For Each loop is adding back the old data to the listbox, along
with the new data.

OK, then how do I delete that old data so it doesn't add it back?
Aug 15 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Ben | last post by:
Hi, I seem to be having a memory management issue with the ListBox control. Using .NET Memory Profiler, the Clear() method does not appear to actually remove references to objects in the list...
2
by: Peter Bailey | last post by:
I have a function courtesy of the newsgroup that clears the list box. I would like to now set the listbox back to its initial state where you can see the first item in the list. The same goes for a...
3
by: google | last post by:
Hello, I am trying to create a listbox that users can select multiple entries on. I want Access to put each on of those selections in a different row on a particular table. This table will also...
8
by: gv | last post by:
Ok, Hi all, new to asp.net. Simple question with web forms I have a Dropdownlist and a listbox, I want to click on and item in the dropdownlist and show items in listbox. that simple I...
2
by: amber | last post by:
Hello I'm keeping this list busy! : Okay, now I'm trying to clear a listbox The way I have it set up, the user can either enter a value into a textbox, then hit a button, and 1 specific record is...
5
by: heddy | last post by:
I have a listbox that gets populated in code by a reader result set from a stored proc on SQL Server 2005. In building this I created a set of test rows in the DB and the code runs fine and...
1
by: WhiteWizard | last post by:
First my apologies, this may be longer than the normal question. I have a windows app (.NET 2.0, VS2005), and I've written a user control that will allow the user to "drag and drop" a directory...
8
by: PeteOlcott | last post by:
http://archive.dojotoolkit.org/nightly/dojotoolkit/dojox/grid/tests/test_change_structure.html I would like to completely understand how GUI controls such as this one are constructed. In the...
15
by: Doogie | last post by:
I have a .net app that a user currently enters a number in a text box, hits a button and a data call is executed. She wants the ability to enter in multiple numbers (up to 100). So to make...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.