1 Replies - 1862 Views - Last Post: 19 April 2013 - 05:06 AM Rate Topic: -----

#1 macphill  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 18-April 13

am trying to add all the values in the total column of the listview

Posted 18 April 2013 - 10:07 PM

am trying to add all the values in the total column of the listview and automatically display the value in a text box: this is the whole code on the form ..
Imports System.Data
Imports System.Data.SqlClient
Public Class Check_Out
    Dim ds, ds1, ds2 As DataSet
    Dim da, da2, da3 As SqlDataAdapter
    Dim cmd, cmd1, cmd2, cmd3 As SqlCommand
    Dim cb As SqlCommandBuilder
    Dim drow, drow1 As DataRow
    Dim dr, dr1, dr2 As SqlDataReader

    Dim con As New SqlConnection("server=.;uid=sa;pwd=june;database=pos;integrated security=false")

    'another code for marquee
    Const marqueeText As String = "Phill concept POs giving you the value for your money "
    Dim sb As New System.Text.StringBuilder
    Dim direction As Boolean = False 'true = left to right, false = right to left



    Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click

    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        'If (ComboBox1.Text = "food") Then

        'End If

        'Dim cmd3 As SqlCommand
        'cmd3 = New SqlCommand("select * from stock where [email protected]_type", con)
        'cmd3.Parameters.AddWithValue("@item_type", ComboBox1.Text)
        'Dim reader2 As SqlDataReader
        'reader2 = cmd3.ExecuteReader()
        'reader2.Read()
        'ComboBox2.Items.Add(reader2.GetString(0))

        'TextBox2.Text = reader2.GetString(1)
        'TextBox3.Text = reader2.GetString(2)
    End Sub

    Private Sub Label6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label6.Click

    End Sub

    Private Sub Check_Out_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer1.Interval = 100
        Timer1.Start()
        Label13.Text = LoginForm1.UsernameTextBox.Text

        Dim cmd11 As New SqlCommand("Select * from stock", con)
        con.Open()
        Dim dr1 As SqlDataReader = cmd11.ExecuteReader
        While dr1.Read
            ComboBox2.Items.Add(dr1.GetValue(0).ToString())
        End While
        ' scrolling text
        Timer2.Enabled = True
        Timer2.Interval = 500

        'code for load combo box
        'Dim cmd3 As SqlCommand
        'cmd3 = New SqlCommand("select * from stock where [email protected]_type", con)
        'cmd3.Parameters.AddWithValue("@item_type", ComboBox1.Text)
        'Dim reader2 As SqlDataReader
        'reader2 = cmd3.ExecuteReader()
        'reader2.Read()
        'ComboBox2.Items.Add(reader2.GetString(0))

    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        TextBox5.Text = Val(TextBox3.Text) * Val(TextBox4.Text)
        cmd2 = New SqlCommand("select * from stock where [email protected]", con)
        ' cmd2.Parameters.AddWithValue("@product_name", ComboBox2.Text)
        cmd2 = New SqlCommand("select * from stock", con)

    End Sub

    Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub Label12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label12.Click

    End Sub

    Private Sub Label13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label13.Click

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        LoginForm1.Show()
        Me.Hide()
    End Sub

    Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged

    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

        Dim arr(6) As String
        Dim itm As ListViewItem

        'Add first item
        arr(0) = TextBox2.Text
        arr(1) = ComboBox2.Text
        arr(2) = ComboBox1.Text
        arr(3) = Val(TextBox3.Text)
        arr(4) = Val(TextBox4.Text)
        arr(5) = Val(TextBox5.Text)
        itm = New ListViewItem(arr)
        ListView1.Items.Add(itm)

    End Sub
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Label12.Text = System.DateTime.Now
    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
        Try


            Dim cmd2 As SqlCommand
            cmd2 = New SqlCommand("select * from stock where [email protected]_name", con)
            cmd2.Parameters.AddWithValue("@product_name", ComboBox2.Text)
            Dim reader1 As SqlDataReader
            reader1 = cmd2.ExecuteReader()
            reader1.Read()
            TextBox2.Text = reader1.GetString(1)
            TextBox3.Text = reader1.GetString(3)
        Catch ex As Exception

        End Try


    End Sub

    Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox1.Enter

    End Sub

    'Private Sub Label1_CursorChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label1.CursorChanged
    '    If Label11.Text = "food" Then
    '        ComboBox2.DataSource = "eggs"
    '        ComboBox2.DataSource = "Milk"


    '    End If
    'End Sub

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        If sb.Length = 0 Then sb.Append(marqueeText)
        If direction Then
            sb.Insert(0, sb(sb.Length - 1))
            sb.Remove(sb.Length - 1, 1)
        Else
            sb.Append(sb(0))
            sb.Remove(0, 1)
        End If
        Me.Text = sb.ToString
    End Sub

    Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged

    End Sub

    Private Sub Label1_ContextMenuStripChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label1.ContextMenuStripChanged

    End Sub

    Private Sub ComboBox1_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedValueChanged

    End Sub

    Private Sub TextBox5_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox5.TextChanged

    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        TextBox7.Text = Val(TextBox1.Text) - Val(TextBox6.Text)
    End Sub

    Private Sub GroupBox2_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox2.Enter

    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        ' For Each ListViewItem As ListViewItem In ListViewItem.SelectedItems

        'ListViewItem.Remove()

        ' Next
    End Sub
   
End Class
Attached Image

Is This A Good Question/Topic? 0
  • +

Replies To: am trying to add all the values in the total column of the listview

#2 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1726
  • View blog
  • Posts: 5,704
  • Joined: 25-September 09

Re: am trying to add all the values in the total column of the listview

Posted 19 April 2013 - 05:06 AM

Loop through the listview using a for...next or for...each loop while accumulating the value in SubItems(4) to a variable. Use said variables .ToString function to display in the textbox.

This would be a good use for a function that takes the listview and the subitem index in as arguments and returns a decimal value
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1