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.
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.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
Any suggestions/advice would be appreciated.




Reply With Quote