firstly thanks for all the help on these forums, I have found it extremely helpfull! Unfortunately I have a problem that I can't quite figure out. I have written a program in vb.net which uses a LogIn screen which opens up a HomePage where you can create messages for other people to see.
I can create new messages but they do not show in my datagridview unless I close the program and re-open it. Then they are present.
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