Hi everyone!
I have a datagrid that is populated with an Excel File. All of the rows in the first column of this file need to be checked upon loading so that the length of its contents will be exactly 17 characters. Here's what I've come up with:

Code:
        private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
        {
            if (dataGridView1.Rows[e.RowIndex].IsNewRow) { return; }
            if (e.ColumnIndex > 0) { return; } /*This line is used to invoke the validation only for the first column (whose index is 0).

            if ((e.FormattedValue.ToString().Length!=17)) /*The contents' length of the first column must be 17 characters*/
            {
                MessageBox.Show(e.RowIndex.ToString());
                
                MessageBox.Show("The field myField must have a length of 17 characters.","Warning: ", MessageBoxButtons.OK,MessageBoxIcon.Error);
                dataGridView1.CurrentCell = this.dataGridView1[0,(byte)e.RowIndex];
                dataGridView1.BeginEdit(true);
                e.Cancel = true;
            }
        }
Suppose I load a file with a row that has 18 characters (or anything different than 17). The CellValidating event doesn't fire unless I click on the cell that doesn't match the validation condition and then try to leave it. In that case, the message box shows up and then the focus is set on that cell for editing.
I need to find a workaround so that the validation will occur upon loading the Excel file, and after closing the message box place the cursor in the first cell (in case there are many) that doesn't match the condition.
Any help will be greatly appreciated! Thanks in advance!