Vb.net UltraWinGrid在单独窗体上刷新按钮按下

Vb.net UltraWinGrid在单独窗体上刷新按钮按下,vb.net,refresh,infragistics,ultrawingrid,Vb.net,Refresh,Infragistics,Ultrawingrid,我有一个.NET项目,其中包括一个UltraWinGrid,用于显示数据库表中的数据。在带有UWG的表单上,我有3个按钮;'“新建数据”、“编辑数据”和“删除数据”。前两个打开的新表单带有用于输入/编辑要保存的数据的控件。save函数工作正常,但是当我关闭表单以查看初始表单(使用UWG)时,数据没有刷新,只有在我关闭并重新打开它时才会刷新 那么,当我按下新表单上的save按钮时,是否有任何方法可以使UWG刷新?(我已经尝试再次调用加载UWG的函数,但这不起作用,因为由于连接原因,我无法使其成为共

我有一个.NET项目,其中包括一个UltraWinGrid,用于显示数据库表中的数据。在带有UWG的表单上,我有3个按钮;'“新建数据”、“编辑数据”和“删除数据”。前两个打开的新表单带有用于输入/编辑要保存的数据的控件。save函数工作正常,但是当我关闭表单以查看初始表单(使用UWG)时,数据没有刷新,只有在我关闭并重新打开它时才会刷新

那么,当我按下新表单上的save按钮时,是否有任何方法可以使UWG刷新?(我已经尝试再次调用加载UWG的函数,但这不起作用,因为由于连接原因,我无法使其成为共享方法)

保存功能代码:

    Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click

    Dim m_cn As New OleDbConnection
    m_cn = m_database.getConnection()


    If txtFirstName.Text = "" Then
        MsgBox("First name cannot be blank")

    ElseIf txtLastName.Text = "" Then
        MsgBox("Last name cannot be blank")

    ElseIf txtAge.Text = "" Then
        MsgBox("Age cannot be blank")

    ElseIf txtPostCode.Text = "" Then
        MsgBox("Postcode cannot be blank")

    Else
        Dim personID As Integer = database.SaveNewPerson(txtFirstName.Text, txtLastName.Text, txtAge.Text, txtPostCode.Text, m_cn)

        MsgBox("Save successful")

        txtFirstName.Text = ""
        txtLastName.Text = ""
        txtAge.Text = ""
        txtPostCode.Text = ""

    End If

End Sub
加载UWG的代码:

 Public Sub getPeople()

    Try
        Dim sql As String = "SELECT * FROM tblPerson"
        Dim cm As New OleDbCommand(sql, m_database.getConnection())
        Dim da As New OleDbDataAdapter(cm)
        Dim dt As New DataTable()
        da.Fill(dt)
        ugData.DataSource = dt

    Catch Ex As Exception
        MsgBox("Could not load people")
    End Try

End Sub

您应该在调用窗体中调用
getPeople
函数,而不是在保存窗体中调用。
您只需要知道保存表单是否正确终止,并且此信息可作为调用
ShowDialog
的返回值。保存人员数据的按钮应将对话框Result属性设置为OK,然后此代码应适用于您

' Open the form that inserts a new person
' Change that name to your actual form class name...
Using fp = new frmPerson()

   ' If the user presses the button to save and everything goes well
   ' we get the DialogResult property from the button pressed 
   if fp.ShowDialog() = DialogResult.OK Then

       ugData.DataSource = Nothing
       getPeople()

   End If
End Using
如果一切顺利,请注意这一点。这意味着,如果在按钮保存过程中出现问题,应阻止窗体关闭,并将
DialogResult
属性更改为None

Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click

    Dim m_cn As New OleDbConnection
    m_cn = m_database.getConnection()


    If txtFirstName.Text = "" Then

        MsgBox("First name cannot be blank")
        Me.DialogResult = DialogResult.None
    ElseIf txtLastName.Text = "" Then
        MsgBox("Last name cannot be blank")
        Me.DialogResult = DialogResult.None
    ElseIf txtAge.Text = "" Then
        MsgBox("Age cannot be blank")
        Me.DialogResult = DialogResult.None
    ElseIf txtPostCode.Text = "" Then
        MsgBox("Postcode cannot be blank")
        Me.DialogResult = DialogResult.None
    Else
        Dim personID As Integer = database.SaveNewPerson(txtFirstName.Text, txtLastName.Text, txtAge.Text, txtPostCode.Text, m_cn)

        MsgBox("Save successful")

        txtFirstName.Text = ""
        txtLastName.Text = ""
        txtAge.Text = ""
        txtPostCode.Text = ""
    End If
End Sub

您应该在调用窗体中调用
getPeople
函数,而不是在保存窗体中调用。
您只需要知道保存表单是否正确终止,并且此信息可作为调用
ShowDialog
的返回值。保存人员数据的按钮应将对话框Result属性设置为OK,然后此代码应适用于您

' Open the form that inserts a new person
' Change that name to your actual form class name...
Using fp = new frmPerson()

   ' If the user presses the button to save and everything goes well
   ' we get the DialogResult property from the button pressed 
   if fp.ShowDialog() = DialogResult.OK Then

       ugData.DataSource = Nothing
       getPeople()

   End If
End Using
如果一切顺利,请注意这一点。这意味着,如果在按钮保存过程中出现问题,应阻止窗体关闭,并将
DialogResult
属性更改为None

Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click

    Dim m_cn As New OleDbConnection
    m_cn = m_database.getConnection()


    If txtFirstName.Text = "" Then

        MsgBox("First name cannot be blank")
        Me.DialogResult = DialogResult.None
    ElseIf txtLastName.Text = "" Then
        MsgBox("Last name cannot be blank")
        Me.DialogResult = DialogResult.None
    ElseIf txtAge.Text = "" Then
        MsgBox("Age cannot be blank")
        Me.DialogResult = DialogResult.None
    ElseIf txtPostCode.Text = "" Then
        MsgBox("Postcode cannot be blank")
        Me.DialogResult = DialogResult.None
    Else
        Dim personID As Integer = database.SaveNewPerson(txtFirstName.Text, txtLastName.Text, txtAge.Text, txtPostCode.Text, m_cn)

        MsgBox("Save successful")

        txtFirstName.Text = ""
        txtLastName.Text = ""
        txtAge.Text = ""
        txtPostCode.Text = ""
    End If
End Sub

嗨,史蒂夫,谢谢你的回复,vb.net的代码会如何变化,因为我不使用或不理解c?嗨,史蒂夫,谢谢你的回复,vb.net的代码会如何变化,因为我不使用或不理解c?