I have a c# .net4 project linked to an EF MySql database model. The main window has a data grid which shows the "EnteredTickets" the user has added to the MySql data base. When the user double clicks on the data grid row of one of the "EnteredTickets" a window opens (called edit) to allow user to edit the "Entered Ticket" and then "save" the edit. Once the edit is saved is completed the "edit" window closes.
What I want to do is refresh the data grid on the main window to show the edited data.
To do this after reading around I believe I need to raise an event and then "handle" this event in the MainWindowxmal.cs. In particular I am following the steps here. As you will see I have added a messagebox to know the event has been raise from the edit window. However I am not handling the event correctly in the mainwindow as the messagebox I have added in the event handler is not displaying "Edit Finished", This is the code I have
In the Edit Window
public partial class EditTicket : Window
{
//public event EventHandler EditFinished;
// Create a custom routed event by first registering a RoutedEventID
// This event uses the bubbling routing strategy
public static readonly RoutedEvent EditFinishedEvent = EventManager.RegisterRoutedEvent(
"EditFinished", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(EditTicket));
// Provide CLR accessors for the event
public event RoutedEventHandler EditFinished
{
add { AddHandler(EditFinishedEvent, value); }
remove { RemoveHandler(EditFinishedEvent, value); }
}
// This method raises the EditFinished event
void RaiseEditFinishedEvent()
{
RoutedEventArgs newEventArgs = new RoutedEventArgs(EditTicket.EditFinishedEvent);
RaiseEvent(newEventArgs);
MessageBox.Show("Raised Routed");
}
The event is raised in the "save" button click by the following code and I get the Messagebox "Raised Routed"
//raise editfinshed event
RaiseEditFinishedEvent();
My problems occur on the Main Window side
The code in the Main Window
public MainWindow()
{
InitializeComponent();
AddHandler(EditTicket.EditFinishedEvent, new RoutedEventHandler(RefreshEnteredTickets));
Application.Current.MainWindow.WindowState = WindowState.Maximized;
}
My handler code is this but not actions
void RefreshEnteredTickets(object sender, RoutedEventArgs e)
{
MessageBox.Show ("Edit Finished");
}
Can any one suggest where I have gone wrong please?