ListView Unbearable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • C# Learner

    ListView Unbearable

    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.BeginU pdate();

    listView.Items. Clear();

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

    items[i] = item;
    }
    listView.Items. AddRange(items) ;

    listView.EndUpd ate();
    }

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

    #2
    Re: ListView Unbearable

    On Mon, 01 Mar 2004 01:15:31 +0000, C# Learner <csharp@learner .here> wrote:
    [color=blue]
    >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.BeginU pdate();
    >
    > listView.Items. Clear();
    >
    > ListViewItem[] items = new ListViewItem[Num];
    > for (int i = 0; i < items.Length; ++i) {
    > ListViewItem item = new ListViewItem(Te xt);
    > item.SubItems.A dd(Text);
    >
    > items[i] = item;
    > }
    > listView.Items. AddRange(items) ;
    >
    > listView.EndUpd ate();
    >}
    >
    >It looks like .NET let me down again; I might have to use another
    >framework for the project due to this.[/color]

    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>.Painti ng = False ... do stuff ... <form>.Painin g = True.

    Comment

    • C# Learner

      #3
      Re: ListView Unbearable

      Steve Jorgensen wrote:
      [color=blue]
      > 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>.Painti ng = False ... do stuff ... <form>.Painin g = True.[/color]

      Yeah, that's what ListView.BeingU pdate() and ListView.EndUpd ate() do
      here. .NET can be very VCL-ish.

      Comment

      • Richard A. Lowe

        #4
        Re: ListView Unbearable

        First I've added microsoft.publi c.dotnet.framew ork.windowsform s.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

        --
        C#, .NET and Complex Adaptive Systems:

        "C# Learner" <csharp@learner .here> wrote in message
        news:OgfJPry$DH A.3500@tk2msftn gp13.phx.gbl...[color=blue]
        > 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.BeginU pdate();
        >
        > listView.Items. Clear();
        >
        > ListViewItem[] items = new ListViewItem[Num];
        > for (int i = 0; i < items.Length; ++i) {
        > ListViewItem item = new ListViewItem(Te xt);
        > item.SubItems.A dd(Text);
        >
        > items[i] = item;
        > }
        > listView.Items. AddRange(items) ;
        >
        > listView.EndUpd ate();
        > }
        >
        > It looks like .NET let me down again; I might have to use another
        > framework for the project due to this.[/color]


        Comment

        • Michael A. Covington

          #5
          Re: ListView Unbearable

          It runs fine here. Does your ListView have any unusual property settings?
          How slow is the PC you're trying it on?


          Comment

          • Chris R

            #6
            Re: ListView Unbearable

            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.

            "C# Learner" <csharp@learner .here> wrote in message
            news:OgfJPry$DH A.3500@tk2msftn gp13.phx.gbl...[color=blue]
            > 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.BeginU pdate();
            >
            > listView.Items. Clear();
            >
            > ListViewItem[] items = new ListViewItem[Num];
            > for (int i = 0; i < items.Length; ++i) {
            > ListViewItem item = new ListViewItem(Te xt);
            > item.SubItems.A dd(Text);
            >
            > items[i] = item;
            > }
            > listView.Items. AddRange(items) ;
            >
            > listView.EndUpd ate();
            > }
            >
            > It looks like .NET let me down again; I might have to use another
            > framework for the project due to this.[/color]


            Comment

            • C# Learner

              #7
              Re: ListView Unbearable

              Richard A. Lowe wrote:
              [color=blue]
              > First I've added microsoft.publi c.dotnet.framew ork.windowsform s.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.[/color]

              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 :(
              [color=blue]
              > Richard[/color]

              Comment

              • C# Learner

                #8
                Re: ListView Unbearable

                Michael A. Covington wrote:
                [color=blue]
                > It runs fine here. Does your ListView have any unusual property settings?[/color]

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

                - View: Details
                - Columns: 5
                [color=blue]
                > How slow is the PC you're trying it on?[/color]

                The other reply I just sent has details on that.

                Comment

                • C# Learner

                  #9
                  Re: ListView Unbearable

                  Chris R wrote:
                  [color=blue]
                  > 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.[/color]

                  I've just tried removing the calls to BeginUpdate() and EndUpdate() and
                  it makes no difference whatsoever.

                  Comment

                  • Jon Skeet [C# MVP]

                    #10
                    Re: ListView Unbearable

                    C# Learner <csharp@learner .here> wrote:

                    <snip>
                    [color=blue]
                    > 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.[/color]

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

                    --
                    Jon Skeet - <skeet@pobox.co m>
                    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

                    If replying to the group, please do not mail me too

                    Comment

                    Working...