Search code examples
c#eventsmdi

How to detect a mdi child's control event?


I have been looking online, but cannot find an answer to what I'm trying to do. I am creating a MDI application, and on a child form is a DataGrid. I need to figure out how to subscribe to the DoubleClick event of that DataGrid on the child form.

So, let's say Form1 is parent. Form2 is child. I have opened up Form2 as such:

Form2 f = new Form2 { Text = "Child", MdiParent = this };
f.Show();

When the user doubleclicks on the datagrid in that form (f), I need to be able to detect it. Can anyone point me in the right direction?

(I hope this was explained clearly)


Solution

  • You can use the myDataGrid.DoubleClick inherited by the DataGrid Class from System.Windows.Forms.Control Class

        private void Form_Load()
        {
            myDataGrid.DoubleClick += MyDataGridOnDoubleClick;
        }
    
        private void MyDataGridOnDoubleClick(object sender, EventArgs eventArgs)
        {
            //throw new NotImplementedException();
        }