首先感谢这些论坛上的所有帮助,我发现它非常有帮助!不幸的是,我有一个问题,我无法弄明白。我在vb.net上编写了一个程序,该程序使用LogIn屏幕打开一个HomePage,您可以在其中创建消息供其他人查看。
我可以创建新邮件,但它们不会显示在我的datagridview中,除非我关闭程序并重新打开它。然后他们在场。
Public Class frmMessage
Dim newMsgRow As Prototype1DataSet.MessagesRow
Dim editMsgRow As Prototype1DataSet.MessagesRow
Private Sub MessagesBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.Validate()
Me.MessagesBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.Prototype1DataSet)
End Sub
Private Sub MessageForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the Prototype1DataSet.Messages table. You can move, or remove it, as needed.'
Me.MessagesTableAdapter.Fill(Me.Prototype1DataSet.Messages)
End Sub
Private Sub btn_SaveMsg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_SaveMsg.Click
'Check if inputs are valid and then saves new message and returns to Home Page'
If CheckDataInputs() Then
If frmHomePage.editMsgFlag = False Then
SaveNewMessage()
ElseIf frmHomePage.editMsgFlag = True Then
EditMessage()
End If
MessageBox.Show("Message saved", Me.Text, MessageBoxButtons.OK)
Me.Hide()
frmHomePage.Show()
End If
End Sub
Private Function CheckDataInputs() As Boolean
'Check if any inputs are left empty'
Dim InputsCheck As Boolean = True
If txt_MsgFrom.Text = "" Then
MessageBox.Show("Please state whom the message is from", Me.Text, MessageBoxButtons.OK)
Me.txt_MsgFrom.Focus()
InputsCheck = False
ElseIf txt_MsgTo.Text = "" Then
MessageBox.Show("Please enter message recipient", Me.Text, MessageBoxButtons.OK)
Me.txt_MsgTo.Focus()
InputsCheck = False
ElseIf txt_Message.Text = "" Then
MessageBox.Show("Please enter a message", Me.Text, MessageBoxButtons.OK)
Me.txt_Message.Focus()
InputsCheck = False
ElseIf txt_MsgStatus.Text = "" Then
MessageBox.Show("Please select message status", Me.Text, MessageBoxButtons.OK)
Me.txt_Message.Focus()
InputsCheck = False
End If
Return InputsCheck
End Function
Private Sub SaveNewMessage()
'Saves new message into Messages table'
newMsgRow = Prototype1DataSet.Messages.NewMessagesRow()
newMsgRow.From = txt_MsgFrom.Text
newMsgRow._To = txt_MsgTo.Text
newMsgRow.Message = txt_Message.Text
newMsgRow.Status = txt_MsgStatus.Text
newMsgRow._Date = date_Msg.Text
Prototype1DataSet.Messages.AddMessagesRow(newMsgRow)
MessagesTableAdapter.Update(Prototype1DataSet)
Prototype1DataSet.Messages.AcceptChanges()
End Sub
End Class
答案 0 :(得分:0)
通常发生在DataGridView数据绑定表中..
如果您已经更新了表格或在表格中进行了一些更改,那么您必须
DataGridView1.DataSource = MyTable
因此表格将重新载入您的DGV ..