private bool gridHasFocus(object sender) { MainFrm mainFrm = sender as MainFrm; bool gridFocus = false; if (mainFrm != null) { DataGridView[] gvs = mainFrm.GetGridViews(); foreach (DataGridView gv in gvs) { if (gv.ContainsFocus) { gridFocus = true; break; } } } return(gridFocus); }