I could not find any remarks on MSDN ListView.Groups Property that empty ListViewGroup will be hidden. Is it by design, or I am missing something? My sample code below will show only "group 2" with item "item1".
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
'
Dim gr = New ListViewGroup("group 1")
ListView1.Groups.Add(gr)
'
Dim gr2 = New ListViewGroup("group 2")
ListView1.Groups.Add(gr2)
'
Dim lvi As New ListViewItem("item1")
ListView1.Items.Add(lvi)
'
gr2.Items.Add(lvi)
End Sub
Updated: Is there are any way to show ListViewGroup without adding dummy item
For now the only workaround idea I have is to use collapsible listview (Vista and up)
this method makes sure the ListViewGroup shows
void MakeSureListViewGroupHeaderShows(ListView lv)
{
foreach (ListViewGroup lvg in lv.Groups)
{
if (lvg.Items.Count == 0)
{
// add empty list view item
ListViewItem lvi = new ListViewItem(string.Empty);
lvi.Group = lvg;
lv.Items.Add(lvi);
}
else
{
// remove our dummy list view item
foreach (ListViewItem lvi in lvg.Items)
{
if (lvi.Text == string.Empty)
{
lvi.Remove();
}
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With