ListBox update

G

Gavaskar

Hello

I've got a listBox on a Windows form in which I add data to it ,as needed,
or so I think.

Basically I'm cycling oversome data and if I find some matches, I call my
helper function AddtoList(str)

public void somefunc()
{
AddToList("sometexttodisplay");
}

public void AddToList(String s)
{
string sOut = datetime.TimeOfDat.ToString() + s ;
listBox1.Add(sOut);

}

Now the the gets displayed, but after the program has stopped running. How
do I have the listbox update when the line listBox1.Add(sOut); is actually
excuted?
 
G

Gavaskar

Hello

I used the listBox1.Items.Add(sOut); listBox1.Update(); method

At first it seems to work, but I noticed that as I'm adding more strings to
the listbox, I'm not able to use the scroll bar, to scroll down the list,
until I've finished adding data.

Is that something, that putting the list box into a separate thread would
take care of?
 
G

Gavaskar

Ok, Thanks

In your example you start the method RunThread(); in a new thread.

Now what if I wanted to pass data into that method? So the method signature
would be
void RunThread(string s) {.....}

Would I be able to do something like
void StartProcessing()
{
new Thread(RunThread(string s)).Start();
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top