jwcolby
jwcolby at colbyconsulting.com
Fri Nov 19 12:58:42 CST 2010
As it happens, we have solved this problem. The EventArgs class is used to create a new class which is descendant from this EventArgs class. You then add your own properties that you need to pass back. public class DbExpEventArgs : EventArgs { public int recCount; public Exception ex; public SqlException exSql; } RecCount, Ex and SQLEx are properties that I car about in this case. Now I can create an instance of this class and fill in any of the properties, then pass this back to the event handler. John W. Colby www.ColbyConsulting.com On 11/19/2010 12:02 PM, Gustav Brock wrote: > Hi John > > As I've seen it, e returns a collection of properties (or values) from the event, but which is dependant on which object raised the event and what "type" the event was. > I don't recall any methods, for example: > > private string _nodeSelected; > > <snip> > > private void TreeViewMenu_AfterSelect(object sender, TreeViewEventArgs e) > { > _nodeSelected = e.Node.Name; > Console.WriteLine(e.Node.Handle.ToString()); > } > > private void TreeViewMenu_KeyPress(object sender, KeyPressEventArgs e) > { > Console.WriteLine((string)"Key: " + _nodeSelected); > TreeViewAction(); > // Avoid speaker "beep" for not found keyboard entries. > e.Handled = true; > } > > I often use "sender" to obtain the object in question without specifying its name: > > private void dataTableEmployerDataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e) > { > DataGridView dataGridView = (DataGridView)sender; > DataGridViewCell cell = dataGridView[e.ColumnIndex, e.RowIndex]; > if (cell.ColumnIndex.Equals(_columnIndexPassword)) > { > // Check if the new password contains invalid chars. > string password = cell.Value.ToString().Replace(" ", "").Replace("\'", "").Replace("\"", ""); > if (password.Length == 0) > { > // Invalid chars found or password is of zero length. > password = _password; > } > cell.Value = password; > } > } > > /gustav > > >>>> jwcolby at colbyconsulting.com 19-11-2010 17:04:14>>> > The MS "convention" is that an event method raises an event and passes out two parameters, one of > which is EventArg e. > > What is e? > > I need to pass back status from the object raising the event and EventArgs seems like what I should > be using to send back the status, but e has not methods for directly adding status like information. > > Am I supposed to create a status class and have it inherit (descend from) EventArgs? >