您的位置:首页 > 编程语言 > C#

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

2013-08-22 09:00 405 查看
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("当前已是第一页", "提示");

            }

        }



 



 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐