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?