I try to update a dgv of one form from another. The initial form is what I call "stock" where we find a combobox with products and a dgv where those same products appear with their corresponding quantities (that is, 2 columns)
I give the option to add a new product with a button in the "stock" form. The code is:
Private Sub btnProducto_Click(sender As Object, e As EventArgs) Handles btnProducto.Click
Dim productos As New Productos(Me)
productos.Show()
End Sub
On the other hand, in the form "products" there is only one textbox for the name of the new product with a button to save in the BD. I also updated the dgv of the "stock" form:
Public Sub New()
InitializeComponent()
End Sub
Public Sub New(stock As stock)
Me.New()
_stock = stock
End Sub
Private Sub btnProducto_Click(sender As Object, e As EventArgs) Handles btnProducto.Click
Dim stock As New stock
oBaseDatos = New CLSoledb("bd.accdb")
oBaseDatos.Insertar_Servicio(txtProducto.Text, 2)
_stock.rellenarProductosDGV()
Me.Close()
End Sub
In the form of "stock", specifically in the load, I call the method fillDVDproducts () and without problems includes the data in the dgv when accessing the form the first time. When adding the product from the form of "products" and use:
_stock.rellenarProductosDGV()
just fill me in if I leave the messagebox.show ("test"). If I remove the messagebox, the dgv of the "stock" form is not updated, the same products remain as when the "stock" load is loaded. The original method is this:
Public Sub rellenarProductosDGV()
MessageBox.Show("test")
oBaseDatos = New CLSoledb("autovag.accdb")
DSProductos = New DataSet
dgvStock.Rows.Clear()
Dim SentenciaSQL As String = "select nombre,cantidad from ser_Pro where tipo=2"
DSProductos = oBaseDatos.AccionSelect(SentenciaSQL)
For f = 0 To DSProductos.Tables(0).Rows.Count - 1
dgvStock.Rows.Add()
For c = 0 To 1
dgvStock.Item(c, f).Value = DSProductos.Tables(0).Rows(f).Item(c)
Next
Next
End Sub
What I understand is that it can be a problem related to execution times or something like that, since when the program stops with the messagebox if it is able to complete the tasks, otherwise the dgv will not be updated independently of the products that are added from the "products" form to the BD. Any recommendation? thanks