Question How to Merge subitems in same Name

dizondarylb

New member
Joined
Dec 16, 2012
Messages
3
Programming Experience
1-3
pLease help me
How can i merge a subitems in same name of product
listview.jpg
Please help ...
 
Sorry for the unclear description
This is my form
form.jpg
And this is my codes
------> vb.net
Public Class Form1




    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        txtDiscount.Enabled = False
        cbQty.Enabled = False


        cbProduct.Items.Add("Cellphone")
        cbProduct.Items.Add("NetBook")
        cbProduct.Items.Add("Computer")
        cbProduct.Items.Add("TV")
        cbProduct.Items.Add("Aircon")
        cbProduct.Items.Add("Refrigerator")
        cbProduct.Items.Add("Electric Fan")
        cbProduct.Items.Add("Tablet")
        cbProduct.Items.Add("Ipod")
        cbProduct.Items.Add("Mp5")


        cbQty.Items.Add("1")
        cbQty.Items.Add("2")
        cbQty.Items.Add("3")
        cbQty.Items.Add("4")
        cbQty.Items.Add("5")
        cbQty.Items.Add("6")
        cbQty.Items.Add("7")
        cbQty.Items.Add("8")
        cbQty.Items.Add("9")
        cbQty.Items.Add("10")
    End Sub


    Private Sub cbProduct_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles cbProduct.KeyDown
        e.SuppressKeyPress = True


    End Sub
    Private Sub cbProduct_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles cbProduct.KeyPress
    End Sub
    Private Sub cbProduct_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbProduct.SelectedIndexChanged
        If cbProduct.Text = "Cellphone" Then
            txtPrice.Text = 1000
            cbQty.Enabled = True
            cbQty.Focus()
        ElseIf cbProduct.Text = "NetBook" Then
            txtPrice.Text = 1800
            cbQty.Enabled = True
            cbQty.Focus()
        ElseIf cbProduct.Text = "Computer" Then
            txtPrice.Text = 1500
            cbQty.Enabled = True
            cbQty.Focus()
        ElseIf cbProduct.Text = "TV" Then
            txtPrice.Text = 400
            cbQty.Enabled = True
            cbQty.Focus()
        ElseIf cbProduct.Text = "Aircon" Then
            txtPrice.Text = 1200
            cbQty.Enabled = True
            cbQty.Focus()
        ElseIf cbProduct.Text = "Refrigerator" Then
            txtPrice.Text = 700
            cbQty.Enabled = True
            cbQty.Focus()
        ElseIf cbProduct.Text = "Electric Fan" Then
            txtPrice.Text = 200
            cbQty.Enabled = True
            cbQty.Focus()
        ElseIf cbProduct.Text = "Tablet" Then
            txtPrice.Text = 1700
            cbQty.Enabled = True
            cbQty.Focus()
        ElseIf cbProduct.Text = "Ipod" Then
            txtPrice.Text = 800
            cbQty.Enabled = True
            cbQty.Focus()
        ElseIf cbProduct.Text = "Mp5" Then
            txtPrice.Text = 500
            cbQty.Enabled = True
            cbQty.Focus()
        ElseIf cbProduct.Text = "" Then
            cbQty.Enabled = False
        End If
    End Sub
    Private Sub txtDiscount_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtDiscount.KeyPress
        Dim total As Double = (Val(txtPrice.Text) * Val(cbQty.Text)) - ((Val(txtPrice.Text) * Val(cbQty.Text)) * Val(txtDiscount.Text) / 100)
        Dim listv As String = cbProduct.Text
        If Asc(e.KeyChar) = Keys.Enter Then
            Dim lv As ListViewItem = ListView1.Items.Add(cbProduct.Text)
            lv.SubItems.Add(cbQty.Text)
            lv.SubItems.Add(txtPrice.Text)
            lv.SubItems.Add(txtDiscount.Text + "%")
            lv.SubItems.Add(total)
            txtDiscount.SelectAll()
        End If
        If (Microsoft.VisualBasic.Asc(e.KeyChar) < 48) _
               Or (Microsoft.VisualBasic.Asc(e.KeyChar) > 57) Then
            e.Handled = True
        End If
        If (Microsoft.VisualBasic.Asc(e.KeyChar) = 8) Then
            e.Handled = False
        End If
    End Sub


    Private Sub cbQty_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles cbQty.KeyPress
        If Asc(e.KeyChar) = Keys.Enter Then
            If cbQty.Text = "" Or cbQty.Text = 0 Then
                txtDiscount.Enabled = False
            Else
                txtDiscount.Enabled = True
                txtDiscount.Focus()
                txtDiscount.SelectAll()
            End If
        End If
        If (Microsoft.VisualBasic.Asc(e.KeyChar) < 48) _
               Or (Microsoft.VisualBasic.Asc(e.KeyChar) > 57) Then
            e.Handled = True
        End If
        If (Microsoft.VisualBasic.Asc(e.KeyChar) = 8) Then
            e.Handled = False
        End If
    End Sub


    Private Sub txtDiscount_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtDiscount.TextChanged
        If txtDiscount.Text = Nothing Then
            txtDiscount.Text = 0
            txtDiscount.SelectAll()
        ElseIf txtDiscount.Text >= 100 Then
            txtDiscount.Text = 100
            txtDiscount.SelectAll()
        End If
    End Sub
End Class

_____________________________________
Then this is my PROBLEM together with the result that I would like to see. thank you for helping me :)
problem.jpg
 

Attachments

  • problem.jpg
    problem.jpg
    108.4 KB · Views: 32
Last edited by a moderator:
Presumably what you actually want is to update an existing item if there is one for the same product rather than combine items later on. In that case the course, if not the implementation, is common sense: before you add an item, check whether there is already one for that product. If there is then update that item rather than adding a new one. The ListView.FindItemWithText method can help you there.
 
Back
Top