question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ListView cannot display content normally if ListView.View = View.SmallIcon

See original GitHub issue

.NET version

7.0.5 and 6.0

Issue description

ListView cannot display content normally if View = View.SmallIcon.

As shown in the picture below, in this test code, if you scroll your mouse or click the scroll bar to move down, the ListView will display a white area, which will not display any data normally.

003

Steps to reproduce

Full C# Code with .net 7.0 and Visual Studio 2022

namespace ListViewTest6
{
    internal static class Program
    {
        [STAThread]
        static void Main()
        {
            ApplicationConfiguration.Initialize();
            Application.Run(CreateForm());
        }

        private static Form CreateForm()
        {
            var form = new Form()
            {
                Width = 800,
                Height = 600,
                StartPosition = FormStartPosition.CenterScreen,
            };

            var imgList = new ImageList()
            {
                ColorDepth = ColorDepth.Depth32Bit,
                ImageSize = new Size(32, 32),
            };

            var listView = new ListView()
            {
                Dock = DockStyle.Fill,
                View = View.SmallIcon,

                SmallImageList = imgList,
                OwnerDraw = true,
            };

            listView.DrawColumnHeader += ListView_DrawColumnHeader;
            listView.DrawItem += ListView_DrawItem;
            listView.DrawSubItem += ListView_DrawSubItem;

            var group1 = new ListViewGroup("Group 1");
            var group2 = new ListViewGroup("Group 2");

            listView.Groups.Add(group1);
            listView.Groups.Add(group2);

            for (int n = 0; n < 100; n++)
            {
                var item1 = listView.Items.Add(new ListViewItem("Item 123456789 1-" + n));
                item1.Group = group1;

                var item2 = listView.Items.Add(new ListViewItem("Item 123456789 2-" + n));
                item2.Group = group2;
            }

            form.Controls.Add(listView);
            return form;
        }

        private static void ListView_DrawItem(object sender, DrawListViewItemEventArgs e)
        {
            e.DrawDefault = true;
        }

        private static void ListView_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
        {
            e.DrawDefault = true;
        }

        private static void ListView_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
        {
            e.DrawDefault = true;
        }
    }
}

Issue Analytics

  • State:open
  • Created 5 months ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
roland5572commented, Apr 20, 2023

I have tested the code, it does not work with .net version 6.0

.net version 7.0 and 6.0 test result:

View = View.SmallIcon => error View = View.LargeIcon=> OK View = View.List=> OK View = View.Details=> OK

0reactions
MelonWang1commented, May 6, 2023

@KlausLoeffelmann This issue also repro in .Net 6.0 & 7.0 on win8.1 machine and win10 rs1 machine.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does my listview keep drawing in LargeIcon View?
I have a inherited Listview which standard has to be in Tile Mode. When using this control, the DrawItem gives e.bounds which are...
Read more >
About List-View Controls - Win32 apps
List-view controls can display items in five different views. The control's window style specifies the default view. Additional window styles ...
Read more >
The ListView Control - SAPIEN Information Center
Represents a Windows list view control, which displays a collection of items that can be displayed using one of four different views. ListView...
Read more >
Working with List View Controls
List view controls in Natural can display their data in one of four view modes: icon, small icon, list or report. In icon...
Read more >
ListView (GUI) - Syntax & Usage
List: Shows a small-icon view in list format, which displays the icons in columns. The number of columns depends on the width of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found