473,406 Members | 2,956 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,406 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 1987
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.