I have a listview and by default it is set to large icons, no problems there. But if giving the user a choice I would liek to see details in the options. I have it set to switch between icons and details but in details mode there is a lot of spacing in the first column. Image attached. The code is below showing how I am loading the listview. Also why so much vertical spacing as well.
Code:
Public Sub ListFoldersFiles(ByVal path As String, ByVal lvTemp As ListView, ByVal imgLtemp As ImageList)
' Create a reference to the current directory.
Dim di As New DirectoryInfo(path)
If Directory.Exists(di.ToString) Then
' Create an array representing the files in the current directory.
Dim fi As FileInfo() = di.GetFiles()
Dim fiTemp As FileInfo
Array.Sort(fi, New compclass(SortOrder.Ascending))
lvTemp.Items.Clear()
' Loop through each file in the directory
For Each fiTemp In fi
Dim strImageKey As String = String.Empty
Try
' gets the icon from file
Dim ico As Icon = Icon.ExtractAssociatedIcon(path & fiTemp.Name)
If ico IsNot Nothing Then
Dim bmp As Bitmap = ico.ToBitmap()
strImageKey = bmp.GetHashCode.ToString
imgLtemp.Images.Add(strImageKey, bmp)
Form1.ImageList3.Images.Add(strImageKey, bmp)
End If
Catch ex As Exception
End Try
' split the extension off so we can use just the text.
Dim rFileName As Array = Split(fiTemp.Name, ".")
Dim fname As String = rFileName(0)
' add full name to tag so we can call it later seeing how we
' don't use the extension for the text.
Dim item As New ListViewItem(fname, imgLtemp.Images.Count - 1) With {.Tag = path & fiTemp.Name}
lvTemp.Items.Add(item)
If Form1.tvFolders.SelectedNode.Name <> "Jackson County" Then
item.SubItems.Add(Form1.tvFolders.SelectedNode.Parent.Name)
item.SubItems.Add(fiTemp.Name)
End If
Next fiTemp
End If
End Sub
And here is the listview click event I change to details.
Code:
Private Sub MnuDetails_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MnuDetails.Click
lvFiles.SmallImageList = ImageList3
lvFiles.View = View.Details
' Select the item and subitems when selection is made.
lvFiles.FullRowSelect = True
' Sort the items in the list in ascending order.
lvFiles.Sorting = SortOrder.Ascending
lvFiles.Columns.Add("Title", -1, HorizontalAlignment.Left)
lvFiles.Columns.Add("Tree", 100, HorizontalAlignment.Left)
lvFiles.Columns.Add("Name", -2, HorizontalAlignment.Left)
End Sub
I put it after I created the columns in the above click event but no change that I can see.
If I were you, I would spend a few minutes to read the documentation.
Here is the remarks on the AutoResize method:
Remarks:
Calling the AutoResize method is only effective once the ListView and containing Form have been constructed, and the column is populated with items. If new items are added to the ListView, the column will not resize unless AutoResize is called again.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it. - Abraham Lincoln -
ok, fair enough. so I moved things around, added the autoresize to the detail click, moved the column add to form load before items are added. Gave them a size smaller than the items and when I clicked the detail view I see it AutoResize yet the alignment is the same.
Is it really the column size or where the items are placed?
it just removes the icon while the text stays in the same place.
well, I fixed it. I removed that imagelist and seen it still went over. Then I noticed under the listview properties that an item called "StateImageList" had a image list associated with it. Why? who knows why or when I did that. But it removed the space to the left of the text, now they align correctly. Thanks guys