Hello to everyone,

I have a program that gets some information from the user and updates the database.

I also have two DataGridView, OpenOrders and ItemsInOrder

When the user click on a cell in the OpenOrders a CellChange event is triggered and it updates the ItemsInOrder grid view...

Now after I update the quantity of a product i want to cause that CellChange event to trigger again in order to refresh the ItemsInOrder grid view.

How can i trigger it programmatically?

Thanks in advance!

Are yourd dataGriViews data bound?

Yes and they filled up when the form loads.

I am using Access database by the way

Lets make something clear. You have 2 dgv-s.
1.
dgv1 is OpenmOrders - I assume its meant to insert new Orders (like order`s number, date,...) and there is another dgv2 ItemsInOrder - it holds the items of selected order from dgv1. Am I right?

2.
So dgv1 allows user to add rows, and so does dgv2. Right?

3.in whihc dgv do you have Quantity? It should be in dgv2 - just next column of the Item name.

4.When you want to show ItemsInOrder of selected OepnOrder, what does your code? Does it go every time to the dataBase to look for the Items of the selected order, or if only filters out of the DataTable (which holds all the items of all the orders)?

Ok one picture = 1000 words so here it is

[IMG]http://i52.tinypic.com/35i58ip.jpg[/IMG]

I hope this helps...

And here is how i get the Item In Order from the database

Public Sub dgvOpenOrders_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvOpenOrders.CellClick
        Dim cn As New OleDbConnection(myConnectionString)
        Dim cmd As New OleDbCommand("SELECT ID, OrderDate, TableNum, CustomerName FROM Orders WHERE TableNum=" & dgvOpenOrders.CurrentRow.Cells(1).Value & " AND Status = 0", cn)
        Dim cmd2 As OleDbCommand
        Dim reader As OleDbDataReader



        Dim datasetItems As Integer
        Dim i As Integer


        Dim tempID As Integer

        cmd.Connection.Open()
        'tempID = cmd.ExecuteScalar 'Store the Id of the order selected
        reader = cmd.ExecuteReader()

        reader.Read()
        tempID = reader.Item(0)


        lblDate.Text = reader.Item(1).ToString
        lblTableNum.Text = reader.Item(2).ToString
        lblCustName.Text = reader.Item(3).ToString


        reader.Close()


        cmd.Connection.Close()




        cmd2 = New OleDbCommand("SELECT Products.ProductName AS Product, OrderInfo.Quantity,Products.ProductPrice AS Price FROM OrderInfo,Products WHERE OrderInfo.OrderID = " & tempID & "AND OrderInfo.ProductID = Products.ProductID", cn) 'also add the cost
        Dim adapter As New OleDb.OleDbDataAdapter(cmd2)
        Dim dataset As New DataSet
        Dim total As Decimal


        cmd2.Connection.Open()



        adapter.Fill(dataset)

        datasetItems = dataset.Tables(0).Rows.Count
        dataset.Tables(0).Columns.Add("Total")

        i = 0
        total = 0
        While datasetItems > 0

            dataset.Tables(0).Rows(i).Item("Total") = ((dataset.Tables(0).Rows(i).Item("Quantity")) * (dataset.Tables(0).Rows(i).Item("Price")))
            total += dataset.Tables(0).Rows(i).Item("Total")
            datasetItems -= 1
            i += 1
        End While

        lblTotal.Text = total

        cmd2.Connection.Close()

        dgvItems.DataSource = dataset.Tables(0)
        dgvItems.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
    End Sub

So I want to trigger this subroutine everytime I add an item

Hello to everyone,

I have a program that gets some information from the user and updates the database.

I also have two DataGridView, OpenOrders and ItemsInOrder

When the user click on a cell in the OpenOrders a CellChange event is triggered and it updates the ItemsInOrder grid view...

Now after I update the quantity of a product i want to cause that CellChange event to trigger again in order to refresh the ItemsInOrder grid view.

How can i trigger it programmatically?

Thanks in advance!

Hi,

I think you can use the Datagridview.CellValueChanged event for this, look here.

Thanks for the links, I will read them and I will get back if i have further questions...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.