473,387 Members | 1,724 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,387 software developers and data experts.

listboxes

How can i refresh the contents of a listbox.

On my form I have a listbox.
In the Form_load sub I coded:
listbox.datasource = A (where A is a collection that is populated from a
diskfile at program start)
listbox.displaymember = "Naam"

When the form is displayed the listbox shows the items in the collection.

So far no problem.

Now I add an item to the collection A and want that to show up in my
listbox.
When I do a A.Items.Add() I get a runtime error message "Cannot modify the
Items collection when the DataSource property is set."
When i change the DataSource property to Nothing and than do the Items.Add I
get an empty listbox. What am I doing wrong?

Nov 21 '05 #1
2 1066
This works for me:

Private strValues as new Arraylist
'in the load I fill a arraylist with values from a file
Try
Dim objRead As New IO.StreamReader("c:\values.txt")
Do While objRead.Peek > -1
strValues.Add(objRead.ReadLine)
Loop
objRead.Close()
ListBox1.DataSource = strValues
Catch ex As Exception
MsgBox(ex.ToString)
End Try

'then behind a button I've got code to add a value
strValues.Add("NewValue")
ListBox1.DataSource = Nothing
ListBox1.DataSource = strValues
hth greetz Peter, be aware there's no check if the file exists or anything.

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning.
"Jan Warning" <ja*********@wanadoo.nl> schreef in bericht
news:uT**************@tk2msftngp13.phx.gbl...
How can i refresh the contents of a listbox.

On my form I have a listbox.
In the Form_load sub I coded:
listbox.datasource = A (where A is a collection that is populated from a
diskfile at program start)
listbox.displaymember = "Naam"

When the form is displayed the listbox shows the items in the collection.

So far no problem.

Now I add an item to the collection A and want that to show up in my
listbox.
When I do a A.Items.Add() I get a runtime error message "Cannot modify the Items collection when the DataSource property is set."
When i change the DataSource property to Nothing and than do the Items.Add I get an empty listbox. What am I doing wrong?

Nov 21 '05 #2
Thanks.
I tried that already, but it resulted also in an empty listbox.
When I tried it again, I happened to detect that the listbox is not really
empty, because when I click on it, corresponding data shows up in a second
listbox.
So, the proper information is in the listbox but is not shown for some
reason.
Absolutely no idea why.

"Peter Proost" <pp*****@nospam.hotmail.com> wrote in message
news:e1**************@TK2MSFTNGP10.phx.gbl...
This works for me:

Private strValues as new Arraylist
'in the load I fill a arraylist with values from a file
Try
Dim objRead As New IO.StreamReader("c:\values.txt")
Do While objRead.Peek > -1
strValues.Add(objRead.ReadLine)
Loop
objRead.Close()
ListBox1.DataSource = strValues
Catch ex As Exception
MsgBox(ex.ToString)
End Try

'then behind a button I've got code to add a value
strValues.Add("NewValue")
ListBox1.DataSource = Nothing
ListBox1.DataSource = strValues
hth greetz Peter, be aware there's no check if the file exists or
anything.

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning.
"Jan Warning" <ja*********@wanadoo.nl> schreef in bericht
news:uT**************@tk2msftngp13.phx.gbl...
How can i refresh the contents of a listbox.

On my form I have a listbox.
In the Form_load sub I coded:
listbox.datasource = A (where A is a collection that is populated from a
diskfile at program start)
listbox.displaymember = "Naam"

When the form is displayed the listbox shows the items in the collection.

So far no problem.

Now I add an item to the collection A and want that to show up in my
listbox.
When I do a A.Items.Add() I get a runtime error message "Cannot modify

the
Items collection when the DataSource property is set."
When i change the DataSource property to Nothing and than do the
Items.Add

I
get an empty listbox. What am I doing wrong?


Nov 21 '05 #3

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

Similar topics

0
by: Jeffrey Barish | last post by:
I have an application that produces two listboxes. I would like to be able to select one of the items in the first listbox and one of the items in the second listbox. However, when I make my...
3
by: softengine | last post by:
Can and how do you alter a data view to include a look up field from another data table? The data table of the dataview only has the key, the value I need is in another data table. Can and how...
3
by: Simon Templar | last post by:
I need the following functionality: With 2 listboxes populated from a database with the SAME data, I need any of the listboxes to stop displaying the option when selected at the other listbox. Eg:...
9
by: Susan Bricker | last post by:
Hi. I have two questions ... (1) I want to use a Listbox to enable the user to select 1 or many items from the list. However, I'm having trouble figuring out how to find out t which items have...
4
by: bill yeager | last post by:
I have several template columns inside of a datagrid. Inside of these template columns are databound listboxes: <asp:TemplateColumn HeaderText="Crew Chiefs"> <ItemTemplate> <asp:listbox...
0
by: Terry D | last post by:
I'm having an issue with an ASP.NET page (VS.NET 2003, VB.NET, Oracle back end). The page uses the standard VS.NET grid to display the records from a particular table. The user can edit certain...
1
by: Ryan Ternier | last post by:
I have two listboxes, and allow users to move items between them via the following function: function SwitchList(fbox, tbox){ var arrFbox = new Array(); var arrTbox = new Array(); var...
0
by: Luis Esteban Valencia | last post by:
have a problem and I'm not sure how to handle/fix it. I have three listboxes on my page. The first listbox has a list of software products. When you select an item in the Products listbox, then...
2
by: salad | last post by:
This is a tip on how to speed up listboxes DRAMATICALLY. Persons that would benefit are those that are constantly updating the rowsource of a listbox/combobox in order to filter and sort the data...
0
by: amidala | last post by:
Hello, everyone, i've recently started using C# and i'm rather new to this language. I'm trying to make a small project now that is combining the basic knowledge of programming (according to me :) )....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...

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.