Results 1 to 3 of 3

Thread: [2005] Listview Row Height Workaround Issues

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2007
    Posts
    115

    [2005] Listview Row Height Workaround Issues

    I am trying to allow users to adjust font size and space between rows of a listview. Since listview does not support changing row height directly I tried a workaround of inserting blank rows in between. The problem is the bigger the font, the bigger the blank rows. And when I try to change the font size of the blank row directly, it changes the font size but keeps the row height the same as the big font rows...

    I know this code is a bit messy. Basically it is a listview loaded row by row in a 5 column by 4 row listview. It cycles through pages based on the timer event.

    Code:
    Public Sub TimerFired(ByVal sender As Object, _
               ByVal e As System.EventArgs)
    
            pkgCnt = frm1.lstApts.CheckedItems.Count
       
       	Dim d As Decimal = (pkgCnt / 20)
            numPages = Decimal.Truncate(d)
       
       	If pkgCnt Mod 20 = 0 Then
                numPages = numPages - 1
            End If
       
            Dim tempRowArray(4) As String
            Dim blankRowArray() As String = {"", " ", " ", " ", " "}
            Dim i As Integer = 0 'use for rows
            Dim j As Integer = 0 'used for hotizontal spacing
            Dim sourceIndex As Integer = 0
            Dim destIndex As Integer = 0
            Dim length As Integer = 5
            Dim exitLoop As Boolean = False
            Dim sourceArray(pkgCnt - 1) As Object
    
            frm1.lstApts.CheckedItems.CopyTo(sourceArray, 0)
            ListView1.Items.Clear()
    
            If pkgCnt > 0 Then
                Do Until i > 3 This loads each of the 4 rows
                    sourceIndex = (curPage * 20) + (i * 5)
                    Array.Clear(tempRowArray, 0, 5)
                    Dim lenComp As Integer = pkgCnt - ((curPage * 20) + (i * 5))
                    If length > lenComp Then
                        exitLoop = True
                        length = pkgCnt - ((curPage * 20) + (i * 5))
                    End If
                    Array.Copy(sourceArray, sourceIndex, tempRowArray, destIndex, length)
                    Dim ii As New ListViewItem(tempRowArray)
                    Me.ListView1.Items.Add(ii)
    
                    Dim fnt As New Font("Times New Roman", 12, FontStyle.Regular, GraphicsUnit.Point)
                    For j = 1 To My.Settings.myVertSpace  'This loads the blank rows
                        Dim jj As New ListViewItem(blankRowArray)
                        jj.Font = fnt
                        Me.ListView1.Items.Add(jj)
                    Next
                    
                    If exitLoop Then
                        Exit Do
                    End If
                    i = i + 1
                Loop
               
                 If curPage = numPages Then
                    curPage = 0
                Else
                    '        Debug.WriteLine("increment pages")
                    curPage = curPage + 1
                End If
            End If
        End Sub
    The part in red is where it loads the blank rows. My.Settings.myVertSpace is a number between 0 and 5 that tells it how many blank rows to insert in between.

    Any suggestions/advice would be appreciated.

  2. #2
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,950

    Re: [2005] Listview Row Height Workaround Issues

    I don't think there is any way to set the row heights individually.

    Something you could do is set OwnerDraw and draw the ListView with your own code. This would take some time to do, but you could then have any layout and appearance that you wanted.

    I don't know anything about your app, but rather than having a ListView with multiple sections (separated by blank lines), could you use several ListViews, one for each section? You can still move items between them, so it could still be made to look and behave like one ListView?

    The ListView component does also support groups, but I don't have any experience using that feature.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2007
    Posts
    115

    Re: [2005] Listview Row Height Workaround Issues

    Quote Originally Posted by Bulldog
    I don't think there is any way to set the row heights individually.

    Something you could do is set OwnerDraw and draw the ListView with your own code. This would take some time to do, but you could then have any layout and appearance that you wanted.

    I don't know anything about your app, but rather than having a ListView with multiple sections (separated by blank lines), could you use several ListViews, one for each section? You can still move items between them, so it could still be made to look and behave like one ListView?

    The ListView component does also support groups, but I don't have any experience using that feature.

    Thats an interested idea but it would require some work. I allow the user to move the listview around with arrow keys, plus I allow adjustments to width. I would have to change code everywhere. I was hoping for something simplier. You would think that someone had code for an extended listview tht i could just download and integrate.

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