Having an issue switching a listview from Tile to Details View with groups.

When the list view has groups and the Default View is Tile, when changing the view to Details the first Group is not shown. Its under the column header.

I jerry rigged it with creating a global variable to store the tile size and when switching to details view setting the tile size to a new size of 1,1. When switching back to Tile View setting the Tile Size to the Global Tile Size Stored.

Interested if someone can come up with another, maybe more proper way, of doing this.


You should be able to simulate it with adding a listview, adding 2 groups, adding 2 items, attach an item to each group, and add 1 column.

Set the default View to Tile.

In a button click event change the view to Details. Hopefully, you see my issue.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    ListView1.View = View.Details
    'Uncomment the next line to perform a jerry rig fix
    'ListView1.TileSize = New Size(1, 1)
End Sub
Unhnd_Exception
Deleted Member

Here is a sample that I generated that works well for view switching using a combobox an loads with the form. All works well without issues, and it works with directory files. It switches the look upon change of the combobox. inside the combobox is items Details, List in that order. I hope this helps

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        ListView1.View = View.Details
        Dim sDir As String = "C:\\"
        Dim dDir As New DirectoryInfo(sDir)
        Dim fFileSystemInfo As FileSystemInfo
        ListView1.Columns.Add("Files")
        ListView1.Columns.Add("Attributes")
       
        For Each fFileSystemInfo In dDir.GetFileSystemInfos()
            ListView1.Items.Add(fFileSystemInfo.Name)

        Next
     
    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        Select Case ComboBox1.SelectedIndex
            Case 0
                ListView1.View = View.Details
            Case 1
                ListView1.View = View.List
        End Select
    End Sub

Edited 5 Years Ago by zinnqu: n/a

The problem is when there are groups and the initial state is Tile

Switching from Tile to Details is causing the Group to be behind the column headers.

I modified your code to show the problem

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load
        ListView1.View = View.Tile
        Dim sDir As String = "C:\\"
        Dim dDir As New DirectoryInfo(sDir)
        Dim fFileSystemInfo As FileSystemInfo
        ListView1.Columns.Add("Files")
        ListView1.Columns.Add("Attributes")

        ListView1.Groups.Add(New ListViewGroup("0", "Group1"))

        For Each fFileSystemInfo In dDir.GetFileSystemInfos()
            ListView1.Items.Add(fFileSystemInfo.Name)
            ListView1.Items(ListView1.Items.Count - 1).Group = ListView1.Groups(0)
        Next

    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        Select Case ComboBox1.SelectedIndex
            Case 0
                ListView1.View = View.Details
            Case 1
                ListView1.View = View.Tile
        End Select
    End Sub

Run that and see if the group is behind the column headers when you switch.

If it is you can click on the first item in the list and the group will magically appear.

The problem is when there are groups and the initial state is Tile

Switching from Tile to Details is causing the Group to be behind the column headers.

I modified your code to show the problem

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load
        ListView1.View = View.Tile
        Dim sDir As String = "C:\\"
        Dim dDir As New DirectoryInfo(sDir)
        Dim fFileSystemInfo As FileSystemInfo
        ListView1.Columns.Add("Files")
        ListView1.Columns.Add("Attributes")

        ListView1.Groups.Add(New ListViewGroup("0", "Group1"))

        For Each fFileSystemInfo In dDir.GetFileSystemInfos()
            ListView1.Items.Add(fFileSystemInfo.Name)
            ListView1.Items(ListView1.Items.Count - 1).Group = ListView1.Groups(0)
        Next

    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        Select Case ComboBox1.SelectedIndex
            Case 0
                ListView1.View = View.Details
            Case 1
                ListView1.View = View.Tile
        End Select
    End Sub

Run that and see if the group is behind the column headers when you switch.

If it is you can click on the first item in the list and the group will magically appear.

I think that this is a bug that happens. I have the program loaded on XP and Server 2003 and it works fine. I am not sure what is causing this to happen.

Actually it may be a bug. I just checked it on XP and it DOES NOT DO IT. I'm running it on Server 2008.

This question has already been answered. Start a new discussion instead.