I spent the last couple of days reading my different books and looking at the MSDN documentation, and I just can't get what seems like an extremely simple task to work with.
Here's what I want to do in a nutshell: I have a static DBToolBox class that performs various functions in SQL databases, and I want it to have an error reporting system that is different from the user interface. I want to use an event to signal when the log (DataTable) has been updated to update the new static class itself, a Windows form using a DataGridView. Here is the code I cannot work with:
Alarm Class:
public static class DBTools { public static readonly DataTable ErrorLog = new DataTable(); public static event EventHandler LogUpdated = delegate {};
Reactive class:
public static partial class ErrorWindow : Form { DBToolbox.LogUpdated += ErrorWindow.ErrorResponse; \\the offending event handler: \\invalid token "+=" in class, struct, or interface member declaration \\invalid token ";" in class, struct, or interface member declaration \\'QueryHelper_2._0.DBToolbox.LogUpdated' is a 'field' but is used like a 'type' \\'QueryHelper_2._0.ErrorWindow.ErrorResponse(object)' is a 'method' but is used like a 'type' private void Error_Load(object sender, EventArgs e) { ErrorLogView.DataSource = DBToolbox.ErrorLog; } public void ErrorResponse(object sender) { this.Show(); this.ErrorLogView.DataSource = DBToolbox.ErrorLog; this.ErrorLogView.Refresh(); this.Refresh(); } }
}
What am I doing wrong?
In addition, there are two other solutions that I can execute: Firstly, these are my own DataTable RowUpdated or NewTableRow events, but I'm not sure how to sign this event.
Another event is a DataGridVeiw DataSourceChanged, but I do not know if this means that the event fires when the DataSource address changes, if it changes values.
I also have been pursuing a career in C # for about a week and a half, but I programmed VB2010 about a year before that, so I'm not very familiar with the .NET 4 function library.
source share