DataGridView中实现上一页,上一行,下一行,下一页的功能

DataGridView中实现上一页,上一行,下一行,下一页的功能:
      属性设置:
          SelectionMode——FullRowSelect
          MultiSelct——false
          AllowUserToResizeRows——false
          AllowUserToResizeColumns——false

      //以下的DataGridView在窗口中可视的行数为15。

       private void btnNextRow_Click(object sender, EventArgs e)
        {
            if (dgvPlaneInfo.CurrentCell.RowIndex < dgvPlaneInfo.Rows.Count - 1)
            {
                dgvPlaneInfo.CurrentCell = dgvPlaneInfo[0, dgvPlaneInfo.CurrentCell.RowIndex + 1];
            }
            else
            {
                MessageBox.Show("当前已是最后一行", "提示");
            }
        }

        private void btnLastRow_Click(object sender, EventArgs e)
        {
            if (dgvPlaneInfo.CurrentCell.RowIndex != 0)
            {
                dgvPlaneInfo.CurrentCell = dgvPlaneInfo[0, dgvPlaneInfo.CurrentCell.RowIndex - 1];
            }
            else
            {
                MessageBox.Show("当前已是第一行", "提示");
            }
        }

        private void btnNextPage_Click(object sender, EventArgs e)
        {
            if (dgvPlaneInfo.Rows.Count - dgvPlaneInfo.CurrentCell.RowIndex > 15)
            {
                dgvPlaneInfo.CurrentCell = dgvPlaneInfo[0, dgvPlaneInfo.CurrentCell.RowIndex + 15];
            }
            else if (dgvPlaneInfo.Rows.Count - dgvPlaneInfo.CurrentCell.RowIndex > 1)
            {
                dgvPlaneInfo.CurrentCell = dgvPlaneInfo[0, dgvPlaneInfo.Rows.Count - 1];
            }
            else
            {
                MessageBox.Show("当前已是最后一页", "提示");
            }
        }

        private void btnLastPage_Click(object sender, EventArgs e)
        {
            if (dgvPlaneInfo.CurrentCell.RowIndex > 14)
            {
                dgvPlaneInfo.CurrentCell = dgvPlaneInfo[0, dgvPlaneInfo.CurrentCell.RowIndex - 15];
            }
            else if (dgvPlaneInfo.CurrentCell.RowIndex <= 14 && dgvPlaneInfo.CurrentCell.RowIndex != 0)
            {
                dgvPlaneInfo.CurrentCell = dgvPlaneInfo[0, 0];
            }
            else
            {
                MessageBox.Show("当前已是第一页", "提示");
            }
        }

 
 

你可能感兴趣的:(分页,DataGridView,button,C#,DataGridView,Button,分页)