コード例 #1
0
        public void W058_CustomerEditor_NavigateRows()
        {
            // get CustomerEditor and check it's visible
            Form customerEditor = TestDriver.WidgetGet <Form>("CustomerEditor");
            // get DataGridView
            DataGridView dataGridView = customerEditor.WidgetGet <DataGridView>("dataGridView");

            // check DataGridView has three rows
            Assert.IsTrue(dataGridView.RowCount == 3,
                          string.Format("dataGridView row count: expected 3 and actual is {0}.", dataGridView.RowCount));

            // select row 0
            dataGridView.SelectRow(0);

            // check row 0 is selected
            int[] selectedIndices = dataGridView.SelectedIndices;
            int   selectedRow     = selectedIndices[0];

            Assert.IsTrue(selectedIndices.Length == 1 && selectedRow == 0);

            // check the values of row 0
            dataGridView.AssertRowTextIs(
                new[] { "1", "Muddy", "WATERS", "Mississippi", "Muddy WATERS" }, selectedRow);

            // select row 1 with arrow key
            dataGridView.SendKeys(Keys.ArrowDown);

            // check row 1 is selected
            selectedIndices = dataGridView.SelectedIndices;
            selectedRow     = selectedIndices[0];
            Assert.IsTrue(selectedIndices.Length == 1 && selectedRow == 1);

            // check the values of row 1
            dataGridView.AssertRowTextIs(
                new List <string> {
                "2", "Louis", "ARMSTRONG", "Louisiana", "Louis ARMSTRONG"
            }, 0, selectedRow);

            // select row 2
            dataGridView.SelectRow(2);

            // check row 2 is selected
            selectedIndices = dataGridView.SelectedIndices;
            selectedRow     = selectedIndices[0];
            Assert.IsTrue(selectedIndices.Length == 1 && selectedRow == 2);

            // check the values of row 2
            dataGridView.AssertRowTextIs(
                new[] { "B. B.", "Maryland", "3", "KING", "B. B. KING" }, new List <int> {
                1, 3, 0, 2, 4
            }, selectedRow);
        }