dotnet / dotnet/winforms

The element added to the group is not displayed in the ListView after adding of group

Open
#3,987 5 comments 0 reactions 0 assignees View on GitHub
:beetle: bug area-controls-ListView help wanted
Dominant language
C#
Stars
4.9k
Forks
1.1k
Avg merge
20h 23m
Merged PRs (30d)
103

Description

* .NET Core Version: **5.0.100-rc.1.20420.14**

* Have you experienced this same bug with .NET Framework?: **Yes**, tested in net472, netcoreapp3.1

**Repro steps:**
1. Create application with ListView.
2. Create ListViewGroup
3. Add ListViewItem to ListViewGroup
4. Add ListViewGroup to ListView.
5. Or use attached project [WindowsFormsApp3.zip](https://github.com/dotnet/winforms/files/5271938/WindowsFormsApp3.zip)

**Actual:**
`ListViewItem` is not displayed in `ListView` because `ListItemView.ListView = null`. I think ListView should be set for item when we add group with this item to ListView.

As a result `ListViewItem.AccesibleObject` may either throw `InvalidOperationException`, when attempting to access an item which added to a group, but have not link to the listview (2), or have a stable/incorrect reference to the listview when its group is removed from the listview (3)

**Expected:**
1. `ListViewItem` is displayed in ListView, if added to a group which is then added to a listview.
2. `ListViewItem` has a reference to the listview, when a group is added to the listview
2. `ListViewItem` has a reference to the listview removed, when a group is removed from the listview

**Notes:**

```
var group = new ListViewGroup("Test group");

// this item is not shown in the listview, and doens't have reference to listview
// i.e. item1.ListView = null
ListViewItem item1 = new ListViewItem("You don't see me");
group.Items.Add(item1);
listView2.Groups.Add(group);

// this items is shown in the listview, item2.ListView <-- listView2
ListViewItem item2 = new ListViewItem("You see me", group);
listView2.Items.Add(item2);
```

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.