ListView Unbearable

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

C# Learner

Has anyone else noticed ListView's unbearable flickering?

I have a project containing a list-view with the following:
- View: Details
- Columns: 5

The following code causes the list-view to flicker:

private void TestListView()
{
const int Num = 20;
const string Text = "Test";

listView.BeginUpdate();

listView.Items.Clear();

ListViewItem[] items = new ListViewItem[Num];
for (int i = 0; i < items.Length; ++i) {
ListViewItem item = new ListViewItem(Text);
item.SubItems.Add(Text);

items = item;
}
listView.Items.AddRange(items);

listView.EndUpdate();
}

It looks like .NET let me down again; I might have to use another
framework for the project due to this.
 
Has anyone else noticed ListView's unbearable flickering?

I have a project containing a list-view with the following:
- View: Details
- Columns: 5

The following code causes the list-view to flicker:

private void TestListView()
{
const int Num = 20;
const string Text = "Test";

listView.BeginUpdate();

listView.Items.Clear();

ListViewItem[] items = new ListViewItem[Num];
for (int i = 0; i < items.Length; ++i) {
ListViewItem item = new ListViewItem(Text);
item.SubItems.Add(Text);

items = item;
}
listView.Items.AddRange(items);

listView.EndUpdate();
}

It looks like .NET let me down again; I might have to use another
framework for the project due to this.


I'm new to .NET, so I haven't played with that yet, but when I have problems
with flickering in other environments, I can usually find some way to turn
painting off while updating it to get rid of the flickering. In Access, that
would be <form>.Painting = False ... do stuff ... <form>.Paining = True.
 
Steve said:
I'm new to .NET, so I haven't played with that yet, but when I have problems
with flickering in other environments, I can usually find some way to turn
painting off while updating it to get rid of the flickering. In Access, that
would be <form>.Painting = False ... do stuff ... <form>.Paining = True.

Yeah, that's what ListView.BeingUpdate() and ListView.EndUpdate() do
here. .NET can be very VCL-ish.
 
First I've added microsoft.public.dotnet.framework.windowsforms.controls
this to thread because it's not a C# issue.

What exactly are you seeing and what exactly are the specs of your this new
PC? I have run your code below and it was lightning fast (Athlon 2600 /
Radeon 9700 Pro) for 20, 50 even 1000 items.

Richard
 
It runs fine here. Does your ListView have any unusual property settings?
How slow is the PC you're trying it on?
 
ListView will only need to repaint if you make changes on the currently
visible screen or before the current view. By using Clear, you're starting
over with a blank screen. This causes a Paint to be called when you leave
the test method.

To prevent flicker when the update is off screen, it's actually
necessary to NOT use BeginUpdate and EndUpdate, because these cause screen
updates regardless of whether the update was on the current view or not.
That is, if items 1 - 25 are visible and you change or remove items 50-100,
or if you add items below the current view, it's best to not use the
BeginUpdate and EndUpdate. But if you make changes to the current screen,
or above the current screen, it will require an update to the view.

Chris R.
 
Richard said:
First I've added microsoft.public.dotnet.framework.windowsforms.controls
this to thread because it's not a C# issue.

What exactly are you seeing and what exactly are the specs of your this new
PC? I have run your code below and it was lightning fast (Athlon 2600 /
Radeon 9700 Pro) for 20, 50 even 1000 items.

This is the first time I've seen such bad performance of basic controls
on any system.

I'm using:

- Windows XP Home SP1
- 2.5 GHz Intel Celeron
- 256MB RAM
- 64MB graphics card

I'll attempt to describe what I'm seeing.

When I run the code, the items are added to the list *slowly*. I can
actually see a "line" running through the list-view while the items are
being added. During this time, there is awful flicker too.

This happens every time I run the code.

As I say, I've *only* noticed this with .NET apps; I've never seen this
before with Delphi/VC++ apps.

It looks awful. I couldn't ever make a decent GUI app with this :(
 
Michael said:
It runs fine here. Does your ListView have any unusual property settings?

No, only the following non-defaults (apart from size, etc.):

- View: Details
- Columns: 5
How slow is the PC you're trying it on?

The other reply I just sent has details on that.
 
Chris said:
ListView will only need to repaint if you make changes on the currently
visible screen or before the current view. By using Clear, you're starting
over with a blank screen. This causes a Paint to be called when you leave
the test method.

To prevent flicker when the update is off screen, it's actually
necessary to NOT use BeginUpdate and EndUpdate, because these cause screen
updates regardless of whether the update was on the current view or not.
That is, if items 1 - 25 are visible and you change or remove items 50-100,
or if you add items below the current view, it's best to not use the
BeginUpdate and EndUpdate. But if you make changes to the current screen,
or above the current screen, it will require an update to the view.

Chris R.

I've just tried removing the calls to BeginUpdate() and EndUpdate() and
it makes no difference whatsoever.
 
When I run the code, the items are added to the list *slowly*. I can
actually see a "line" running through the list-view while the items are
being added. During this time, there is awful flicker too.

This happens every time I run the code.

I suggest you post a *complete* program then, rather than just one
method, as others aren't seeing the problems you are.
 
Back
Top