dotnet / dotnet/winforms

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

Open
#9,003 9 comments 0 reactions 1 assignee Claimed by @KlausLoeffelmann View on GitHub
tracking-external-issue
Dominant language
C#
Stars
4.9k
Forks
1.1k
Avg merge
20h 23m
Merged PRs (30d)
103

Description

### .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](https://user-images.githubusercontent.com/88176616/232988465-44bccdd0-2d37-4c8f-9a84-e848ad5da7f2.png)

### 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;
}
}
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.