Refreshing the form after cancellation

  • Thread starter Thread starter Ravi Kumar12233
  • Start date Start date
R

Ravi Kumar12233

Guest
In my windows form i have added a button to enter new record , and when that selected , the button text changes as cancel and the focus will move to first entry field . But if i click cancel without entering any data , the focus is not getting removed .and when i press next record then the focus is removed & i can press add new record button again. Kindly help me how to solve this .below is my code

Private Sub AddnewButton_Click(sender As Object, e As EventArgs) Handles AddnewButton.Click
'MsgBox("you preseed add new button")
Try
With AddnewButton
If .Text = "Add New Record" Then
MSdiesBindingSource.AddNew()
.Text = "Cancel"
Else
RefreshData()
.Text = "Add New Record"
End If

End With
With Size_in_mgTextBox
If (.CanSelect) Then
.Text = String.Empty
.Select()
End If
End With

IsAddNewRecordInProgress = Convert.ToBoolean(AddnewButton.Text = "Cancel")


Catch ex As Exception
MsgBox("An error occured: " & ex.Message.ToString().ToString(),
MsgBoxStyle.OkOnly Or MsgBoxStyle.Information, "Add new Record Failed")
End Try
End Sub
Private Sub RefreshData()
Try
'Me.MSdiesBindingSource.Filter = Nothing
MSdiesTableAdapter.Fill(Me.TrialdatabaseDataSet.MSdies)
MSdiesBindingSource.RemoveFilter()
Catch ex As Exception
MsgBox("Refresh Data Error!")
End Try


End Sub

Basically what i want is when i press [add new record] button , the form goes to edit mode , but when i hit the same button (which is now showing as cancel) it should reset (complete refresh) and allow me to come out of edit mode(exiting the focus from Entry field)

Continue reading...
 
Back
Top