Exemplo n.º 1
0
    /// <summary>
    /// 跳转到某一个单元格
    /// </summary>
    /// <param name="row">行  范围1~RowCount</param>
    /// <param name="col">列  范围1~ColumnCount</param>
    private void Goto()
    {
        if (!MainForm.Instance.SelCsvFormInitialized())
        {
            MessageBox.Show("当前没有打开Csv文件", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            return;
        }

        int row, col;

        if (!int.TryParse(m_RowTextBox.Text, out row))
        {
            row = 1;
        }
        if (!int.TryParse(m_ColTextBox.Text, out col))
        {
            col = ConvertUtility.LetterToNumber(m_ColTextBox.Text);
        }

        DataGridView dataGridView = MainForm.Instance.GetCsvForm().GetDataGridView();

        if (col < 1 || col > dataGridView.ColumnCount || row < 1 || row > dataGridView.RowCount)
        {
            string msgText = string.Format("输入的col或row超出范围.\n接受的范围:\n1 <= row <= {0}\n1 <= col <= {1}\n或\nA <= col <= {2}",
                                           dataGridView.RowCount, dataGridView.ColumnCount, ConvertUtility.NumberToLetter(dataGridView.ColumnCount));
            MessageBox.Show(msgText, "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            return;
        }
        dataGridView.CurrentCell = dataGridView.Rows[row - 1].Cells[col - 1];
        return;
    }