J
Jason
Hello
I've got a situatuion were I'm adding data to a list box, maybe 50,000 items
(strings). While I add this data I would like to be able to scroll up/down
to view the data. I've got a small example which is similar to what I'm
doing. I need help trying to figure out how to scroll while data is being
added. In this example I have a for loop that passes a string to my list
box up to 5000000 times in an attempt to simulate my real life program.
Alll works expect the scroll bar on my list box won't let me scroll until
the for loop has completed.
Any idea how I can fix this?
sing System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace MyListBoxthread
{
public partial class Form1 : Form
{
public delegate void AddListItem(String myString);
public AddListItem myDelegate;
public Form1()
{
InitializeComponent();
myDelegate = new AddListItem(AddListItemMethod);
}
private void Form1_Load(object sender, EventArgs e)
{
}
public void AddListItemMethod(string mystring)
{
myListBox.Items.Add(mystring);
//myListBox.Update();
}
private void button1_Click(object sender, EventArgs e)
{
Thread myThread = new Thread(new ThreadStart(ThreadFunction));
myThread.Start();
}
private void ThreadFunction()
{
MyThreadClass MyThreadObject = new MyThreadClass(this);
MyThreadObject.run();
}
}
public class MyThreadClass
{
Form1 myform;
public MyThreadClass(Form1 form)
{
myform = form;
}
string myString;
public void run()
{
for (int i = 1; i < 500000; i++)
{
myString = "Step number " + i.ToString() + "
excuted";
myform.Invoke(myform.myDelegate, new object[] {
myString });
}
MessageBox.Show("Done");
}
}
}
I've got a situatuion were I'm adding data to a list box, maybe 50,000 items
(strings). While I add this data I would like to be able to scroll up/down
to view the data. I've got a small example which is similar to what I'm
doing. I need help trying to figure out how to scroll while data is being
added. In this example I have a for loop that passes a string to my list
box up to 5000000 times in an attempt to simulate my real life program.
Alll works expect the scroll bar on my list box won't let me scroll until
the for loop has completed.
Any idea how I can fix this?
sing System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace MyListBoxthread
{
public partial class Form1 : Form
{
public delegate void AddListItem(String myString);
public AddListItem myDelegate;
public Form1()
{
InitializeComponent();
myDelegate = new AddListItem(AddListItemMethod);
}
private void Form1_Load(object sender, EventArgs e)
{
}
public void AddListItemMethod(string mystring)
{
myListBox.Items.Add(mystring);
//myListBox.Update();
}
private void button1_Click(object sender, EventArgs e)
{
Thread myThread = new Thread(new ThreadStart(ThreadFunction));
myThread.Start();
}
private void ThreadFunction()
{
MyThreadClass MyThreadObject = new MyThreadClass(this);
MyThreadObject.run();
}
}
public class MyThreadClass
{
Form1 myform;
public MyThreadClass(Form1 form)
{
myform = form;
}
string myString;
public void run()
{
for (int i = 1; i < 500000; i++)
{
myString = "Step number " + i.ToString() + "
excuted";
myform.Invoke(myform.myDelegate, new object[] {
myString });
}
MessageBox.Show("Done");
}
}
}