Results 1 to 9 of 9

Thread: [RESOLVED] listview column spacing

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337

    Resolved [RESOLVED] listview column spacing

    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
    Attached Images Attached Images  

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337

    Re: listview column spacing

    anybody have any idea?

  3. #3
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: listview column spacing

    Try calling the AutoResize method of the column header.
    Code:
    lvFiles.Columns(0).AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent)
    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 -

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337

    Re: listview column spacing

    Thanks stanav,

    I put it after I created the columns in the above click event but no change that I can see.

  5. #5
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: listview column spacing

    Quote Originally Posted by phpman View Post
    Thanks stanav,

    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 -

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337

    Re: listview column spacing

    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?

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337

    Re: listview column spacing

    any other ideas? anybody?

  8. #8
    Frenzied Member
    Join Date
    Jul 2011
    Location
    UK
    Posts
    1,335

    Re: listview column spacing

    You have a gift; I can't get anything that looks like the layout in your attachment.

    What happens if you set
    Code:
      lvFiles.SmallImageList = Nothing

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337

    Re: listview column spacing

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width