Further Misery

  • Thread starter Thread starter C# Learner
  • Start date Start date
C

C# Learner

Even a ListBox causes large amounts of flicker when adding items:

private void TestListBox()
{
listBox.BeginUpdate();

listBox.Items.Clear();
for (int i = 0; i < 20; ++i) {
listBox.Items.Add("test");
}

listBox.EndUpdate();
}

Removing the BeginUpdate()/EndUpdate() calls has no effect.

Is anyone else experiencing this?
 
C# Learner said:
Even a ListBox causes large amounts of flicker when adding items:

private void TestListBox()
{
listBox.BeginUpdate();

listBox.Items.Clear();
for (int i = 0; i < 20; ++i) {
listBox.Items.Add("test");
}

listBox.EndUpdate();
}

Removing the BeginUpdate()/EndUpdate() calls has no effect.

Is anyone else experiencing this?

I just ran your test and experienced no flickering. I suspect there is
something wrong with your system or your .NET setup.

Erik
 
Agreed.

Do you have other threads in your application?

Are there other processes in the system that are consuming processor
resource(s) while your application is running?

Check the CPU usage --
 
C# Learner said:
Even a ListBox causes large amounts of flicker when adding items:

private void TestListBox()
{
listBox.BeginUpdate();

listBox.Items.Clear();
for (int i = 0; i < 20; ++i) {
listBox.Items.Add("test");
}

listBox.EndUpdate();
}

Is anyone else experiencing this?

i've had this problem before, and i traced my problem to the Clear()
call... it seems to force the window to be repainted. if you remove the
clear that should fix the flickering (or at least it did in my case).
 
Pat said:
i've had this problem before, and i traced my problem to the Clear()
call... it seems to force the window to be repainted. if you remove the
clear that should fix the flickering (or at least it did in my case).

I've just tried putting the Clear() call into an event handler of
another button, so one button clears and the other adds the items. I
think you're right -- it doesn't look half as bad like this.

With the list view, though, just adding items (without the clear) looks
"slow"; though not half as bad as when Clear() is first called.
 
Have you thought about changing your approach to this problem
Intead of adding individual items evey time, use the built in data binding capabilities.

Try this code

int itemCount = 100

string [] items = new string [itemCount]

for(int i = 0; i < itemCount; i++

items = "test " + i.ToString()


this.listBox1.DataSource = items

In affect it produces the same result, except that it will only cause one refresh. If you want to change the list, just set a new datasource. I used an array in this sample just for ease. You could just as easily use an arraylist (for dynamic lists).

I hope this helps a little bit with you miss conception of .net.. I know this same sort of problem killed me until I changed the way I developed..

Cheers

Eddie de Bea
MCSD
 
Eddie said:
Have you thought about changing your approach to this problem.
Intead of adding individual items evey time, use the built in data binding capabilities..

Try this code:

int itemCount = 100;

string [] items = new string [itemCount];

for(int i = 0; i < itemCount; i++)
{
items = "test " + i.ToString();
}

this.listBox1.DataSource = items;

In affect it produces the same result, except that it will only cause one refresh. If you want to change the list, just set a new datasource. I used an array in this sample just for ease. You could just as easily use an arraylist (for dynamic lists)..

I hope this helps a little bit with you miss conception of .net.. I know this same sort of problem killed me until I changed the way I developed...


Yeah, it doesn't help, unfortunately.

Thanks anyway.
 
Can you tell us a little more about your system? (CPU speed, whether
there's an unusual video system, etc.?)

I am wondering if there is something wrong with your video driver.
 
Back
Top