[RESOLVED] Listview with inner groups
Hi
I have a problem over a month now and I can’t solve it.
I have a ListView with 3 columns date, name and price.
Now I want to create three groups.
The one group under the other with totals and SubTotals and ordered by name and dates.
For example I have these values to my ListView.
Code:
Date Name Money
20/11/2016 Abdul 12,35 €
25/11/2016 Fabiano 32,85 €
20/11/2016 John 9,52 €
30/12/2016 Paavo 85,62 €
30/12/2016 Sabas 847,22 €
20/11/2016 Babs 35,47 €
20/11/2016 Kaan 112,85 €
25/11/2016 Ealair 512,65 €
30/12/2016 Nacio 54,32 €
25/11/2016 Lado 47,51 €
And I want the result to be like that.
Code:
20/11/2016 Name Money
Abdul 12,35 €
Babs 35,47 €
John 9,52 €
Kaan 112,85 €
Sum of day 170,19 €
25/11/2016
Ealair 512,65 €
Fabiano 32,85 €
Lado 47,51 €
Sum of day 593,01 €
Sum Of month 763,20 €
30/12/2016
Nacio 54,32 €
Paavo 85,62 €
Sabas 847,22 €
Sum of day 987,16 €
Sum of month 987,16 €
Total 1.750,36 €
Any help?
How I can do that.
1 Attachment(s)
Re: Listview with inner groups
That doesn't make a lot of sense. This is how ListView Groups look:
Attachment 143321
1 Attachment(s)
Re: Listview with inner groups
How about a listbox with tabstops?
Attachment 143323
Code:
Imports System.Runtime.InteropServices
Public Class Form1
<DllImport("user32.dll")>
Private Shared Function SendMessage(
ByVal hWnd As IntPtr,
ByVal wMsg As Integer,
ByVal wParam As IntPtr,
ByVal lParam As IntPtr) As Integer
End Function
Private Sub SetTabStops(ByVal listBox As ListBox, ByVal tabStops() As Integer)
Const LB_SETTABSTOPS As Integer = &H192
Dim pinnedValues As GCHandle
pinnedValues = GCHandle.Alloc(tabStops, GCHandleType.Pinned)
Dim ptr As IntPtr = pinnedValues.AddrOfPinnedObject()
SendMessage(listBox.Handle, LB_SETTABSTOPS, New IntPtr(tabStops.Length), ptr)
pinnedValues.Free()
listBox.Refresh()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ListBox1.Items.Add("20/11/2016" & vbTab & "Name" & vbTab & "Money")
ListBox1.Items.Add("" & vbTab & "Abdul" & vbTab & "12,35 €")
ListBox1.Items.Add("" & vbTab & "Babs" & vbTab & "35,47 €")
ListBox1.Items.Add("" & vbTab & "John" & vbTab & "9,52 €")
ListBox1.Items.Add("" & vbTab & "Kaan" & vbTab & "112,85 €")
ListBox1.Items.Add("")
ListBox1.Items.Add("Sum of day" & vbTab & "" & vbTab & "170,19 €")
ListBox1.Items.Add("")
ListBox1.Items.Add("25/11/2016")
ListBox1.Items.Add("" & vbTab & "Ealair" & vbTab & "512,65 €")
ListBox1.Items.Add("" & vbTab & "Fabiano" & vbTab & "32,85 €")
ListBox1.Items.Add("" & vbTab & "Lado" & vbTab & "47,51 €")
ListBox1.Items.Add("")
ListBox1.Items.Add("Sum of day" & vbTab & "" & vbTab & "593,01 €")
ListBox1.Items.Add("Sum of month" & vbTab & "" & vbTab & "763,20 €")
ListBox1.Items.Add("")
ListBox1.Items.Add("30/12/2016")
ListBox1.Items.Add("" & vbTab & "Nacio" & vbTab & "54,32 €")
ListBox1.Items.Add("" & vbTab & "Paavo" & vbTab & "85,62 €")
ListBox1.Items.Add("" & vbTab & "Sabas" & vbTab & "847,22 €")
ListBox1.Items.Add("")
ListBox1.Items.Add("Sum of day" & vbTab & "" & vbTab & "987,16 €")
ListBox1.Items.Add("Sum of month" & vbTab & "" & vbTab & "987,16 €")
ListBox1.Items.Add("")
ListBox1.Items.Add("Total" & vbTab & "" & vbTab & "1.750,36 €")
SetTabStops(ListBox1, New Integer() {100, 200})
End Sub
End Class
Re: Listview with inner groups
Dear .paul.
If i take your example inside group1 must I must have other groups let say group1-1, group1-2, group1-2... and inside Group2 must have group2-1, group2-2, group3-3....
I try your solution with tabstops but I have a problem how to filter the months under looping.
Any other idea?
Thank you
1 Attachment(s)
Re: Listview with inner groups
Ok. I put these in a text file...
Quote:
20/11/2016 Abdul 12,35 €
25/11/2016 Fabiano 32,85 €
20/11/2016 John 9,52 €
30/12/2016 Paavo 85,62 €
30/12/2016 Sabas 847,22 €
20/11/2016 Babs 35,47 €
20/11/2016 Kaan 112,85 €
25/11/2016 Ealair 512,65 €
30/12/2016 Nacio 54,32 €
25/11/2016 Lado 47,51 €
Edit: The 3 fields (date, name, money) should be separated by a vbtab character (chr(9))
I tried again with the listview. My code will work if you're loading all of your items at the same time, from a text file, or an array of lines (rows)
Attachment 143341
Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim lines() As String = IO.File.ReadAllLines("filename.txt", System.Text.Encoding.Default)
Array.Sort(lines)
Dim daySum As Decimal = 0
Dim monthSum As Decimal = 0
Dim totalSum As Decimal = 0
Dim last As Date
Dim this As Date
Dim blankItem As ListViewItem
Dim sumItem As ListViewItem
For Each line As String In lines
Dim fields() As String = line.Split(Chr(9))
Date.TryParseExact(fields(0), "dd/MM/yyyy", Nothing, Nothing, this)
If last = Nothing Then
last = this
End If
If Not ListView1.Groups(fields(0)) Is Nothing Then
Dim i As ListViewItem = ListView1.Items.Add(New ListViewItem(fields.Skip(1).ToArray))
ListView1.Groups(fields(0)).Items.Add(i)
Dim d As Decimal
Decimal.TryParse(fields(2), _
Globalization.NumberStyles.AllowCurrencySymbol Or Globalization.NumberStyles.Currency, _
Globalization.CultureInfo.GetCultureInfo("fr-FR"), d)
daySum += d
Else
If Not last.Day = this.Day Then
blankItem = ListView1.Items.Add(New ListViewItem(New String() {""}))
ListView1.Groups(last.ToString("dd/MM/yyyy")).Items.Add(blankItem)
sumItem = ListView1.Items.Add(New ListViewItem(New String() {"Sum of day", daySum.ToString("#.00 €")})) 'change to .ToString("c")
sumItem.Font = New Font(sumItem.Font, sumItem.Font.Style Or FontStyle.Bold)
ListView1.Groups(last.ToString("dd/MM/yyyy")).Items.Add(sumItem)
monthSum += daySum
daySum = 0
If Not (last.Month = this.Month And last.Year = this.Year) Then
sumItem = ListView1.Items.Add(New ListViewItem(New String() {"Sum of month", monthSum.ToString("#.00 €")})) 'change to .ToString("c")
sumItem.Font = New Font(sumItem.Font, sumItem.Font.Style Or FontStyle.Bold)
ListView1.Groups(last.ToString("dd/MM/yyyy")).Items.Add(sumItem)
totalSum += monthSum
monthSum = 0
End If
last = this
End If
ListView1.Groups.Add(fields(0), fields(0))
Dim i As ListViewItem = ListView1.Items.Add(New ListViewItem(fields.Skip(1).ToArray))
ListView1.Groups(fields(0)).Items.Add(i)
Dim d As Decimal
Decimal.TryParse(fields(2), _
Globalization.NumberStyles.AllowCurrencySymbol Or Globalization.NumberStyles.Currency, _
Globalization.CultureInfo.GetCultureInfo("fr-FR"), d)
daySum += d
End If
Next
blankItem = ListView1.Items.Add(New ListViewItem(New String() {""}))
ListView1.Groups(last.ToString("dd/MM/yyyy")).Items.Add(blankItem)
sumItem = ListView1.Items.Add(New ListViewItem(New String() {"Sum of day", daySum.ToString("#.00 €")})) 'change to .ToString("c")
sumItem.Font = New Font(sumItem.Font, sumItem.Font.Style Or FontStyle.Bold)
ListView1.Groups(last.ToString("dd/MM/yyyy")).Items.Add(sumItem)
monthSum += daySum
sumItem = ListView1.Items.Add(New ListViewItem(New String() {"Sum of month", monthSum.ToString("#.00 €")})) 'change to .ToString("c")
sumItem.Font = New Font(sumItem.Font, sumItem.Font.Style Or FontStyle.Bold)
ListView1.Groups(last.ToString("dd/MM/yyyy")).Items.Add(sumItem)
totalSum += monthSum
sumItem = ListView1.Items.Add(New ListViewItem(New String() {"Total", totalSum.ToString("#.00 €")})) 'change to .ToString("c")
sumItem.Font = New Font(sumItem.Font, sumItem.Font.Style Or FontStyle.Bold)
ListView1.Groups(last.ToString("dd/MM/yyyy")).Items.Add(sumItem)
End Sub
End Class
Re: Listview with inner groups
Ok.
Now it works.... Finally after a month...
Thank you so....
Re: Listview with inner groups
Don't forget to mark your thread RESOLVED.
To the right above your original question - Thread tools menu