Answer the question
In order to leave comments, you need to log in
How to solve ListBox issue in C#?
I have such a problem. The program determines whether the given IP address is available, if it is available, then an entry is created in the ListBox with acc. IP address. I do it like this:
Ping pingSender = new Ping();
IPAddress address;
String str;
PingReply reply;
str = textBox1.Text + "." + textBox2.Text + "." + textBox3.Text + "." + textBox4.Text;
IPAddress.TryParse(str, out address);
reply = pingSender.Send(address);
if (reply.Status == IPStatus.Success) listBox1.Items.Add(str);
Answer the question
In order to leave comments, you need to log in
To handle windows rendering events in a long loop, use Application.DoEvents().
for (int i = 0; i < 100; i++)
{
listBox1.Items.Add(i);
Application.DoEvents();
System.Threading.Thread.Sleep(1000);
}
Rsa97 is right, but this is not such a trivial task for a beginner (a non-beginner knows what threads are and would not ask)
you can do this by stuffing all the code into void DoScan ()
further in the place where the code was put Thread t = new Thread (DoScan) ;
t.Start();
but that's not all, so there will be errors when adding an element to the list, so you need to replace
on the
BeginInvoke(new MethodInvoker(delegate
{
if (reply.Status == IPStatus.Success) listBox1.Items.Add(str);
}));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question