U
unba1300
Guest
Hi. I'm using a listview to show a scrollable list of about 25 categories, but I'd like to group the categories into a few subjects and then have a header (title) for each subject. Any suggestions? Thanks.
Sub PopulateItemList
Dim oldChar As String 'current alpha
Dim newChar As String 'new alpha .. next product starting with new alpha
Dim recData(3) As String 'product and size
'fill Items list with records
lvwItems.Clear
Cursor1 = SQL1.ExecQuery("SELECT ID, Product, Size FROM "& StockTable &" ORDER BY Product Asc")
numRec = Cursor1.RowCount
lvwItems.Clear
For i = 0 To numRec -1
Cursor1.Position = i
recData(0) = Cursor1.GetInt("ID")
recData(1) = Cursor1.GetString("Product")
recData(2) = Cursor1.GetString("Size")
'test for new Alpha .. if so show new alpha prior to item list eg: C Cake
newChar = recData(1).SubString2(0,1)
If newChar <> oldChar Then
lvwItems.AddSingleLine(newChar)
oldChar = newChar
End If
'using .AddTwoLines2 allowing me to specify return value for click events ie.. items db ID and items list position (i) 0 start
'this is regex'd on click to variables itemID & itemPos
lvwItems.AddTwoLines2(recData(1) , recData(2 ),recData(0) & "," & i)
Next
Cursor1.Close
End Sub
Sub FormatLists
'format listview Items
lvwItems.Width = 500dip
lvwItems.Height = 560dip
lvwItems.Color = 0xFF4682B4 'SteeleBlue
lvwItems.ScrollingBackgroundColor = Colors.Transparent
lvwItems.SingleLineLayout.ItemHeight = 24
lvwItems.SingleLineLayout.Label.Top = 0
lvwItems.SingleLineLayout.Label.Left = 5dip
lvwItems.SingleLineLayout.Label.Height=24dip
lvwItems.SingleLineLayout.Label.TextSize = 16
lvwItems.SingleLineLayout.Label.TextColor= Colors.DarkGray
lvwItems.TwoLinesLayout.ItemHeight = 36dip
lvwItems.TwoLinesLayout.Label.Top = 0
lvwItems.TwoLinesLayout.Label.Left = 20dip
lvwItems.TwoLinesLayout.Label.Width = 290dip
lvwItems.TwoLinesLayout.Label.Height = 36dip
lvwItems.TwoLinesLayout.Label.Gravity = Gravity.CENTER_VERTICAL
lvwItems.TwoLinesLayout.Label.TextColor = Colors.White
lvwItems.TwoLinesLayout.Label.TextSize = 20
lvwItems.TwoLinesLayout.SecondLabel.Top = 0
lvwItems.TwoLinesLayout.SecondLabel.Left = 330dip
lvwItems.TwoLinesLayout.SecondLabel.Width = 170dip
lvwItems.TwoLinesLayout.SecondLabel.Height = 36dip
lvwItems.TwoLinesLayout.SecondLabel.Gravity = Gravity.CENTER_VERTICAL
lvwItems.TwoLinesLayout.SecondLabel.TextColor = Colors.White
lvwItems.TwoLinesLayout.SecondLabel.TextSize = 20
' ....................
LV.SingleLineLayout.ItemHeight = 100dip
LV.SingleLineLayout.Label.TextSize = 20
LV.SingleLineLayout.Label.TextColor = Colors.Yellow
LV.SingleLineLayout.Label.Gravity = Gravity.CENTER
LV.TwoLinesLayout.ItemHeight = 50dip
LV.TwoLinesLayout.Label.TextColor = Colors.White
LV.TwoLinesLayout.Label.TextSize = 16
LV.TwoLinesLayout.SecondLabel.TextColor = Colors.Green
LV.TwoLinesLayout.SecondLabel.TextSize = 12
For i = 1 To 10
LV.AddSingleLine("Category #" & i)
For a = 1 To 20
LV.AddTwoLines("Item #" & i&"."&a, "This is the second line.")
'LV.AddTwoLinesAndBitmap("Item #" & i, "This is the second line.", Bitmap1)
Next
Next
Thank you very much for taking the time to do that. It should work for my needs.Here is a sample that displays a ListView as you typed above ..
The Listview_Click will not process if user clicks on a Title/Header .
Cheers mj