0

How can i call LoadProducts() form User Control to other class, after i added new users the DataGrid from user control must be realoaded

From User Control (UserM.vb)

Public Sub LoadProducts()
    UsersDataGrid.Rows.Clear()
    Dim i As Integer = 0
    cn.Open()

    cm = New MySqlCommand("SELECT * FROM tblusers where usertype like '%Cashier%'or username like '%Manager%'", cn)
    dr = cm.ExecuteReader
    While dr.Read
        i += 1
        UsersDataGrid.Rows.Add(i, dr.Item("useridnum").ToString, dr.Item("fullname").ToString, dr.Item("username").ToString, dr.Item("usertype").ToString)

    End While
    cn.Close()


End Sub

From Add User (AddUser.vb)

Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
    Try
            MsgBox("User Added Successfully!", vbInformation)
                //LoadProducts method from user control
        End If
    Catch ex As Exception

    End Try
End Sub
James
  • 235
  • 1
  • 2
  • 10
  • 1
    https://learn.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/events/walkthrough-declaring-and-raising-events – Hans Passant Sep 12 '20 at 13:08
  • Is the form containing the user control opening the `AddUser` form in the first place? – jmcilhinney Sep 12 '20 at 14:27
  • The User Control Only Holds the DataGridView , The AddUser have different form – James Sep 12 '20 at 14:39
  • If they are in 2 different forms, what is the relation between the forms? Could you provide more details? – 大陸北方網友 Sep 14 '20 at 02:39
  • Does "UserM" display "AddUser"? If so, display it with `ShowDialog()` so that code STOPS in "UserM". When "AddUser" is dismissed, code back in "UserM" will continue and you can simply call `LoadProducts()` directly since you are in the UserControl itself... – Idle_Mind Sep 18 '20 at 19:12
  • Does this answer your question? [Communicate between two windows forms in C#](https://stackoverflow.com/questions/1665533/communicate-between-two-windows-forms-in-c-sharp) – Peter Duniho Feb 21 '21 at 17:56

1 Answers1

-1

You could put the data output into a text file then read the text file to get the input, the text file will have to be closed for the data to save then your need to wait for about 2200ms for Windows not to see it as being used by a different processor to be able to read it from the second form

So you may want to use about 3 text files or you can put the output the data to a website or server then get the data from the second form

Dharman
  • 30,962
  • 25
  • 85
  • 135
witch
  • 11
  • 2