0 Replies - 924 Views - Last Post: 04 August 2012 - 02:05 AM Rate Topic: -----

#1 vbnewbeginer  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 25-July 12

Update/Bring back the value or quantity of the deleted ITEMS in DGV

Posted 04 August 2012 - 02:05 AM

I made a Pricelist module with a Quotation module. Im using a DataGridView when selecting an item, and when you select it, the item will display in the textbox, and you can input the quantity you want and computes for the amount, the add button works fine, the items you selected and the quantity was displayed in the Quotatioin Datagrid, but my problem is when I deleted the item, its quantity did not properly updated or restore in the Pricelist Datagrid..

Ex. I selected an item where its stocks is 30 and I input 5 as its quantity, then when I deleted it in the quotation, the value of the updated quantity in the Pricelist became 5..

Here is my code in the ADD button:

 Private Sub addBtn_Buttonclicked(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addBtn.Buttonclicked
        add = "Added"
        minus = "Sold"

        StocksTextBox.Text = Val(StocksTextBox.Text) - Val(QuantityTextBox.Text)
        If StocksTextBox.Text <= 0 Then
            MessageBox.Show("Item '" & DescriptionTextBox.Text & "' Stocks will be Empty    ", "Invalid Input  ", MessageBoxButtons.OK, MessageBoxIcon.Information)
        ElseIf StocksTextBox.Text <= 9 Then
            MessageBox.Show("Item '" & DescriptionTextBox.Text & "' Stocks is Low   ", "Item Information  ", MessageBoxButtons.OK, MessageBoxIcon.Information)
            gdpcccon = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\GDPCC\gdpcc.mdb")
            Dim cmd As New OleDbCommand
            Dim strUpdate As String = "update priceTable set [Stocks] = '" & StocksTextBox.Text & "' where ID = " & IDTextBox.Text
            gdpcccon.Open()
            cmd = New OleDbCommand(strUpdate, gdpcccon)
            cmd.ExecuteNonQuery()

            gdpcccon.Close()
            datagridshow()

            AddItemToListView()


            QuantityTextBox.Text = ""
            QuantityTextBox.Enabled = True
            Me.PriceTableBindingSource.CancelEdit()

        Else
            gdpcccon = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\GDPCC\gdpcc.mdb")
            Dim cmd As New OleDbCommand
            Dim strUpdate As String = "update priceTable set Status = '" & minus & "', [Quantity] = '" & QuantityTextBox.Text & "', [Stocks] = '" & StocksTextBox.Text & "' where ID = " & IDTextBox.Text
            gdpcccon.Open()
            cmd = New OleDbCommand(strUpdate, gdpcccon)
            cmd.ExecuteNonQuery()
            MessageBox.Show("Item '" & DescriptionTextBox.Text & "' was Added   ", "Item Information ", MessageBoxButtons.OK, MessageBoxIcon.Information)
            gdpcccon.Close()
            datagridshow()

            AddItemToListView()



            QuantityTextBox.Enabled = True
            QuantityTextBox.Text = ""
            DescriptionTextBox.Text = ""
            CodeTextBox.Text = ""
            Regular_ColorTextBox.Text = ""
            Wood_FinishTextBox.Text = ""

            RadioButton2.Checked = False
            RadioButton1.Checked = False
            Me.PriceTableBindingSource.CancelEdit()

        End If

    End Sub





Here is the code for the Delete item:

Private Sub btnDelete_Buttonclicked(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Buttonclicked
        Me.PriceTableTableAdapter.FillByID(Me.GdpccDataSet.priceTable, IDTextBox2.Text)
        TextBox9.Text = IDTextBox2.Text


        If ListView1.SelectedItems.Count > 0 AndAlso MessageBox.Show("Do you want to delete this item?", "Confirm", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
            StocksTextBox1.Text = Val(TextBox7.Text) + Val(StocksTextBox1.Text)
            gdpcccon = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\GDPCC\gdpcc.mdb")
            Dim cmd As New OleDbCommand
            Dim strUpdate As String = "update priceTable set [Stocks] = '" & StocksTextBox1.Text & "' where ID = " & TextBox6.Text
            gdpcccon.Open()
            cmd = New OleDbCommand(strUpdate, gdpcccon)
            cmd.ExecuteNonQuery()


            MessageBox.Show("Item '" & DescriptionTextBox1.Text & "' Stocks, Updated Successfully   ", " ", MessageBoxButtons.OK, MessageBoxIcon.Information)
            gdpcccon.Close()
            datagridshow()


            ListView1.SelectedItems(0).Remove()



        Else

            IDTextBox2.Text = TextBox8.Text
            MessageBox.Show("Please Select Data to Delete")
        End If
    End Sub





Some screenshots:
Attached Image
Attached Image
Attached Image
Attached Image

Is This A Good Question/Topic? 0
  • +

Page 1 of 1