[dba-VB] What is EventArg?

Gustav Brock Gustav at cactus.dk
Fri Nov 19 11:02:04 CST 2010


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?

-- 
John W. Colby
www.ColbyConsulting.com 





More information about the dba-VB mailing list