listbox not refreshing

sgtmoody

Member
Joined
Jul 10, 2007
Messages
5
Programming Experience
1-3
I have an odd problem I'm working on a programs that loads data from a text file into a listbox. the text file contains multiple types of data but the list box only displays names from the file.
when you load up the program it loads all the names into the listbox and all works fine and gets displayed. I have button on the form to add new data, it stores the new data to the file and adds the name to the listbox.
VB.NET:
//get data from user
//add data to file
//add name to listbox
listbox.items.add(name)
problem is when I add the name to the listbox nothing shows up. the data gets added to the file just fine but the listbox doesn't get updated. I have tried listbox.refresh and update to no avail. however when I restart the program the newly added name shows up.
I know it used to update just fine but I have done allot of work to the program and added lots of code since then.
Did I change something somewhere with out knowing it that doesn't let it update while the program is running? its probably just some weird bug with my code but I thought I would give it shot and see if anyone might know something.

BTW i'm working with vb.net 2005
 
Try these things in this order:

Call the refresh command for the control you are trying to "refresh"

If this does not work add the command Application.DoEvents()

If this does not work try to refresh the parent.

If neither of those work try all three at the same time

If none of those work post your code and I should be able to figure out what is wrong.
 
show us the code you use to add the new name (from user input) to the listbox

when you add items to the listbox, the listbox automatically updates itself to show the new item unless you're adding a bunch of items to a listbox in one run in which you use the SuspendLayout and ResumeLayout methods
 
here is the sub routine where I add the user input to the file and to the listbox. Like I stated earlier it worked just fine before now it just seems that the listbox doesn't refresh any more.
VB.NET:
    Public Sub addGame(ByVal name As String, ByVal key As String)
        Dim oWrite As System.IO.StreamWriter
        Dim fileName As String = String.Concat(My.Application.Info.DirectoryPath, "/Names.txt")

        oWrite = IO.File.AppendText(fileName)        
        oWrite.WriteLine(des.Encrypt(name))//simple encryption of the text file
        oWrite.WriteLine(des.Encrypt(key))//simple encryption of the text file
        oWrite.Close()
        lstNames.Items.Add(name)
    End Sub
 
Back
Top