10 Replies - 1150 Views - Last Post: 08 February 2016 - 11:18 AM Rate Topic: -----

#1 Razor20   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 06-January 16

How to add a total in the last row of Subitems in Listview?

Posted 08 February 2016 - 10:02 AM

I know how to get the total of one column in ListView,
But I Dont know how to put the total of that column in the last row of that column.....
Attached Image

Here's my code on how to get the total
Attached Image

Please help me guyssss....

Is This A Good Question/Topic? 0
  • +

Replies To: How to add a total in the last row of Subitems in Listview?

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14776
  • View blog
  • Posts: 59,069
  • Joined: 12-June 08

Re: How to add a total in the last row of Subitems in Listview?

Posted 08 February 2016 - 10:12 AM

... and what? Does it not give the right value? Are you not adding one last row with that value in it to the listview?
Was This Post Helpful? 0
  • +
  • -

#3 Razor20   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 06-January 16

Re: How to add a total in the last row of Subitems in Listview?

Posted 08 February 2016 - 10:33 AM

All I want is to add or put the total to the last row of "Subitems(3)" as you can see to my screenshot..
I know how to get the total but I dont know how to put it into last row of column 3 of the listview..
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14776
  • View blog
  • Posts: 59,069
  • Joined: 12-June 08

Re: How to add a total in the last row of Subitems in Listview?

Posted 08 February 2016 - 10:34 AM

How are you adding rows now?
Was This Post Helpful? 0
  • +
  • -

#5 Razor20   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 06-January 16

Re: How to add a total in the last row of Subitems in Listview?

Posted 08 February 2016 - 10:39 AM

 con.ConnectionString = "server=localhost;userid=root;database=payroll_system;"
        con.Open()
        Dim EmpPayroll As String
        EmpPayroll = "SELECT Employee_Name, Gross_Income, Total_Deductions, Net_Income FROM employees_payroll WHERE Payroll_From >= @Date1 And Payroll_To <= @Date2 ORDER BY Employee_Name ASC"
        com = New MySqlCommand(EmpPayroll, con)

        With com
            .Connection = con
            .Parameters.AddWithValue("@Date1", DateTimePicker4.Text.Trim)
            .Parameters.AddWithValue("@Date2", DateTimePicker3.Text.Trim)
        End With
        reader = com.ExecuteReader()

        ListView1.Items.Clear()
        While reader.Read()
            Dim List As ListViewItem

            List = ListView1.Items.Add(reader.GetString(0))
            List.SubItems.Add(reader.GetString(1))
            List.SubItems.Add(reader.GetString(2))
            List.SubItems.Add(reader.GetString(3))

            Dim TotalNetIncome As Double = 0
            Dim TempNodeNet As ListViewItem
            Dim TempDblNetPay As Double

            'HERE'S THE CODE TO GET THE TOTAL OF COLUMN 3...
            For Each TempNodeNet In ListView1.Items
                If Double.TryParse(TempNodeNet.SubItems.Item(3).Text, TempDblNetPay) Then
                    TotalNetIncome += TempDblNetPay
                End If
            Next



I put it into Label for a mean time..
I want to put it into the last item of column 3
Attached Image
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14776
  • View blog
  • Posts: 59,069
  • Joined: 12-June 08

Re: How to add a total in the last row of Subitems in Listview?

Posted 08 February 2016 - 10:52 AM

You would figure that if you are creating ListViewItems and then adding them to the listview.. you could make a list view item where the 0, 1, and 2 columns are empty and the 3 column is the total price.
Was This Post Helpful? 0
  • +
  • -

#7 Razor20   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 06-January 16

Re: How to add a total in the last row of Subitems in Listview?

Posted 08 February 2016 - 10:55 AM

Can you show one example?
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14776
  • View blog
  • Posts: 59,069
  • Joined: 12-June 08

Re: How to add a total in the last row of Subitems in Listview?

Posted 08 February 2016 - 10:56 AM

Dude - you wrote the code earlier when you are getting data back from the database.. unless I am over assuming and you didn't write that code in post #5.
Was This Post Helpful? 0
  • +
  • -

#9 Razor20   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 06-January 16

Re: How to add a total in the last row of Subitems in Listview?

Posted 08 February 2016 - 11:02 AM

Here's my code dude....
Im just asking a help..
Im just a novice dude,...

 Private Sub btnGenerate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGenerate.Click
        con.ConnectionString = "server=localhost;userid=root;database=payroll_system;"
        con.Open()
        Dim EmpPayroll As String
        EmpPayroll = "SELECT Employee_Name, Gross_Income, Total_Deductions, Net_Income FROM employees_payroll WHERE Payroll_From >= @Date1 And Payroll_To <= @Date2 ORDER BY Employee_Name ASC"
        com = New MySqlCommand(EmpPayroll, con)

        With com
            .Connection = con
            .Parameters.AddWithValue("@Date1", DateTimePicker4.Text.Trim)
            .Parameters.AddWithValue("@Date2", DateTimePicker3.Text.Trim)
        End With
        reader = com.ExecuteReader()

        ListView1.Items.Clear()
        While reader.Read()
            Dim List As ListViewItem

            List = ListView1.Items.Add(reader.GetString(0))
            List.SubItems.Add(reader.GetString(1))
            List.SubItems.Add(reader.GetString(2))
            List.SubItems.Add(reader.GetString(3))

            Dim TotalNetIncome As Double = 0
            Dim TempNodeNet As ListViewItem
            Dim TempDblNetPay As Double

            For Each TempNodeNet In ListView1.Items
                If Double.TryParse(TempNodeNet.SubItems.Item(3).Text, TempDblNetPay) Then
                    TotalNetIncome += TempDblNetPay
                End If
            Next

            Dim total As Double = TotalNetIncome
            Label3.Text = "₱" & "" & FormatNumber(Math.Round(total))


        End While
        con.Close()
    End Sub


Was This Post Helpful? 0
  • +
  • -

#10 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14776
  • View blog
  • Posts: 59,069
  • Joined: 12-June 08

Re: How to add a total in the last row of Subitems in Listview?

Posted 08 February 2016 - 11:03 AM

Yeah, I got that from your previous post.

Now I am wondering - did you even write that? If so you can follow what I said and add a new row to the listview.
Was This Post Helpful? 0
  • +
  • -

#11 IronRazer   User is offline

  • Custom Control Freak
  • member icon

Reputation: 1533
  • View blog
  • Posts: 3,860
  • Joined: 01-February 13

Re: How to add a total in the last row of Subitems in Listview?

Posted 08 February 2016 - 11:18 AM

If you understand the code that you have, you will understand that you are adding your new ListViewItems (rows) to the Listview 1 at a time in the While Loop with these 5 lines.
           Dim List As ListViewItem

           List = ListView1.Items.Add(reader.GetString(0)) 'puts text in 1st column
           List.SubItems.Add(reader.GetString(1)) 'puts text in 2nd column
           List.SubItems.Add(reader.GetString(2)) 'puts text in 3rd column
           List.SubItems.Add(reader.GetString(3)) 'puts text in 4th column



So, simply use similar code to add 1 more ListViewItem (row) to the ListView after your While Loop has ended. Add blank strings to all of the items except for the 4th column where you would add your total.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1