public void FixMainGridCurrentRowIndexOnRefocus()
        {
            AddDataForSetList();
            CreateControllers(typeof(SetList));
            ParentGrid.Focus();
            Assert.AreEqual(1, View.SetMouseCursorToDefaultCount,
                            "SetMouseCursorToDefaultCount after focusing parent grid");
            Controller.Populate(); // Populate parent and main grids
            Assert.IsTrue(ParentGrid.Focused, "ParentGrid.Focused after Populate");
            Assert.AreEqual(2, View.SetMouseCursorToDefaultCount,
                            "SetMouseCursorToDefaultCount after Populate");
            MainGrid.Focus();
            Assert.AreEqual(3, View.SetMouseCursorToDefaultCount,
                            "SetMouseCursorToDefaultCount after focusing main grid");
            MainGridController.CreateAndGoToNewRow();
            int mainGridNewRowIndex = MainGrid.CurrentRowIndex;

            ParentGrid.Focus();
            // Simulate the problem that occurs when switching focus from the main grid to the
            // parent grid. If the main grid's current row is the new row before focusing the
            // parent grid, then, on focusing the parent grid, the new row is removed, so the
            // main grid's last existing row becomes its current row.
            MainGrid.MakeRowCurrent(mainGridNewRowIndex - 1);
            Assert.AreEqual(mainGridNewRowIndex - 1, MainGrid.CurrentRowIndex,
                            "Main grid current row index after focus switched back to parent grid");
            // Now test the fix. When focus is switched back to the main grid, we want to
            // restore currency to the new row.
            MainGrid.Focus();
            Assert.AreEqual(mainGridNewRowIndex, MainGrid.CurrentRowIndex,
                            "Main grid current row index after focus switched back to main grid");
            Assert.IsTrue(ParentGrid.Enabled,
                          "Parent grid enabled after focus switched back to main grid");
        }
 public void FocusGrids()
 {
     CreateControllers(typeof(SetList));
     ParentGrid.Focus();
     Assert.IsFalse(MainGrid.Focused,
                    "MainGrid.Focused after ParentGrid.Focus");
     Assert.AreEqual(1, MainGrid.CellColorScheme.InvertCount,
                     "MainGrid.CellColorScheme.InvertCount after ParentGrid.Focus");
     Assert.AreEqual(1, MainGrid.DisableCount,
                     "MainGrid.DisableCount after ParentGrid.Focus");
     Assert.AreEqual(1, MainGrid.EnableCount,
                     "MainGrid.EnableCount after ParentGrid.Focus");
     Assert.IsTrue(MainGrid.Enabled, "MainGrid.Enabled after ParentGrid.Focus");
     Assert.IsTrue(ParentGrid.Focused,
                   "ParentGrid.Focused after ParentGrid.Focus");
     Assert.AreEqual(1, ParentGrid.CellColorScheme.RestoreToDefaultCount,
                     "ParentGrid.CellColorScheme.RestoreToDefaultCount after ParentGrid.Focus");
     Assert.AreEqual(1, View.SetMouseCursorToWaitCount,
                     "SetMouseCursorToWaitCount after ParentGrid.Focus");
     Assert.AreEqual(1, View.SetMouseCursorToDefaultCount,
                     "SetMouseCursorToDefaultCount after ParentGrid.Focus");
     Controller.FocusUnfocusedGridIfAny();
     Assert.IsTrue(MainGrid.Focused,
                   "MainGrid.Focused after FocusUnfocusedGridIfAny #1");
     Assert.AreEqual(1, MainGrid.CellColorScheme.RestoreToDefaultCount,
                     "MainGrid.CellColorScheme.RestoreToDefaultCount after FocusUnfocusedGridIfAny #1");
     Assert.IsFalse(ParentGrid.Focused,
                    "ParentGrid.Focused after FocusUnfocusedGridIfAny #1");
     Assert.AreEqual(1, ParentGrid.CellColorScheme.InvertCount,
                     "ParentGrid.CellColorScheme.InvertCount after FocusUnfocusedGridIfAny #1");
     Controller.FocusUnfocusedGridIfAny();
     Assert.IsFalse(MainGrid.Focused,
                    "MainGrid.Focused after FocusUnfocusedGridIfAny #2");
     Assert.AreEqual(2, MainGrid.CellColorScheme.InvertCount,
                     "MainGrid.CellColorScheme.InvertCount after FocusUnfocusedGridIfAny #2");
     Assert.IsTrue(ParentGrid.Focused,
                   "ParentGrid.Focused after FocusUnfocusedGridIfAny #2");
     Assert.AreEqual(2, ParentGrid.CellColorScheme.RestoreToDefaultCount,
                     "ParentGrid.CellColorScheme.RestoreToDefaultCount after FocusUnfocusedGridIfAny #2");
     Controller.FocusUnfocusedGridIfAny();
     Assert.IsTrue(MainGrid.Focused,
                   "MainGrid.Focused after FocusUnfocusedGridIfAny #3");
 }
 public void OnParentGridRowEntered()
 {
     AddDataForSetList();
     CreateControllers(typeof(SetList));
     Assert.IsFalse(MainGrid.Focused, "MainGrid.Focused initially");
     Assert.IsFalse(ParentGrid.Focused, "ParentGrid.Focused initially");
     Assert.IsFalse(MainGridController.IsFixingFocus, "IsFixingFocus initially");
     MainGrid.Focus();
     Assert.AreEqual(1, View.SetMouseCursorToDefaultCount,
                     "SetMouseCursorToDefaultCount after focusing main grid");
     Controller.Populate(); // Populate parent and main grids
     Assert.AreEqual("Event 2 of 2", View.StatusBarText,
                     "StatusBarText after Populate");
     Assert.AreEqual(1, View.OnParentAndMainGridsShownAsyncCount,
                     "OnParentAndMainGridsShownAsyncCount after Populate");
     Assert.IsFalse(MainGrid.Focused, "MainGrid.Focused after Populate");
     Assert.IsTrue(ParentGrid.Focused, "ParentGrid.Focused after Populate");
     Assert.AreEqual(2, MainGrid.CellColorScheme.InvertCount,
                     "MainGrid.CellColorScheme.InvertCount after Populate");
     Assert.AreEqual(2, ParentGridController.BindingList.Count,
                     "Parent list count after Populate");
     Assert.AreEqual(2, MainGridController.FirstVisibleColumnIndex,
                     "Main grid FirstVisibleColumnIndex after Populate");
     Assert.IsFalse(MainGridController.GetBindingColumn("Date").IsVisible,
                    "Is Date column to be shown?");
     Assert.IsTrue(MainGridController.GetBindingColumn("SetNo").IsVisible,
                   "Is SetNo column to be shown?");
     Assert.AreEqual(6, MainGridController.BindingList.Count,
                     "Main list count after Populate"); // Includes new row
     Assert.IsTrue(MainGridController.IsFixingFocus, "IsFixingFocus after Populate");
     Assert.AreEqual(0, ParentGridController.FirstVisibleColumnIndex,
                     "Main grid FirstVisibleColumnIndex after Populate");
     Assert.AreEqual(2, View.SetMouseCursorToDefaultCount,
                     "SetMouseCursorToDefaultCount after Populate");
     // Emulate the unwanted internal logic of DataGridView that, following the end of
     // Populate, causes an extra validation of the first main grid row, even though the
     // parent grid is focused.  Without the workaround we are about to test, this
     // would switch focus to the main grid and make its first row current, neither of
     // which we want. See the documentation for MainGridController.IsFixingFocus.
     MainGridController.OnRowValidated(0);
     // Confirm that the workaround was executed.
     Assert.IsFalse(MainGridController.IsFixingFocus,
                    "IsFixingFocus after OnRowValidated");
     MainGrid.Focus();
     Assert.AreEqual("Set 6 of 6", View.StatusBarText,
                     "StatusBarText when main grid focused");
     MainGridController.OnRowEnter(1);
     Assert.AreEqual("Set 2 of 6", View.StatusBarText,
                     "StatusBarText when 2nd main grid row entered");
     ParentGrid.Focus();
     Assert.AreEqual("Event 2 of 2", View.StatusBarText,
                     "StatusBarText after focusing parent grid");
     ParentGridController.OnRowEnter(0);
     Assert.AreEqual("Event 1 of 2", View.StatusBarText,
                     "StatusBarText when 1st parent selected");
     Assert.AreEqual(4, MainGridController.BindingList.Count,
                     "Main list count when 1st parent selected"); // Includes insertion row
     View.StatusBarText = string.Empty;                           // Simulates editor window deactivated.
     ParentGridController.OnWindowActivated();
     Assert.AreEqual("Event 1 of 2", View.StatusBarText,
                     "StatusBarText when editor window reactivated");
 }