我有一个特定形式的datagridview。在该表单中有一个添加和更新按钮,它将接受详细信息,当单击完成按钮时,我想更新网格视图。但似乎我无法做到这一点,因为我正在从另一个表单添加/更新详细信息。
第一个表单(绑定数据,进入更新/添加按钮表单):
Private Sub bindStudentsData()
Dim db As New Database()
DataGridView1.DataSource = Nothing
DataGridView1.DataSource = New BindingSource(db.getStudentList(), Nothing)
End Sub
Private Sub addBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addBtn.Click
Dim sf As New StudentForm()
sf.Show()
End Sub
Private Sub updateBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles updateBtn.Click
Dim sid As String = DataGridView1.SelectedRows(0).Cells("studentid").Value
Dim sf As New StudentForm(sid)
sf.Show()
End Sub
*通过使用 .show() 之前的表单保持打开状态并打开另一个表单
然后在输入详细信息并单击完成第二个表格后:
Private Sub doneBtm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles doneBtm.Click
Dim db As New Database()
If type Is "add" Then
'go to add
MsgBox(type)
Else
'go to update
db.updateStudentDetails(sid, astudentnumberText.Text, afirstnameText.Text,
_alastnameText.Text, amiddlenameText.Text, asectionText.Text)
Me.Close()
End If
End Sub
单击第二个表单上的完成按钮后,我需要在第一个表单中重新绑定 datagridview。我怎么能那样做?有任何想法吗?谢谢!