C#、.NET、winfrom实现上一条、下一条、首记录、尾记录

版权声明:本文为博主原创文章,转载请附上博文链接! https://blog.csdn.net/qq_41890694/article/details/87724398

C#、.NET、winfrom实现上一条、下一条、首记录、尾记录


作者: 张国军_Suger
开发工具与关键技术:Visual Studio 2015、C#、.NET、winfrom

      由于本人之前做C#、.NET、WCF项目是一直想要这种效果,想了许久,虽然能勉强实现,但却不是我所想要的,因此我后来也找了很多资料,最后我通过查找资料结合起来想出我想要的代码便实现我想要的功能,相信有些朋友也找这种实现,希望能帮到您。
实现截图:
C#、.NET、winfrom实现上一条_下一条_首记录_尾记录C#、.NET、winfrom实现上一条_下一条_首记录_尾记录
实现代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 实现上一条_下一条_首记录_尾记录
{
    public partial class FRM_实现上一条_下一条_首记录_尾记录 : Form
    {
        public FRM_实现上一条_下一条_首记录_尾记录()
        {
            InitializeComponent();
        }
        //首页
        private void btn_ShouYe_Click(object sender, EventArgs e)
        {
            if (dgvShiYan.CurrentCell == dgvShiYan[dgvShiYan.CurrentCell.ColumnIndex, 0])
            {
                MessageBox.Show("已经是首行啦!");
            }
            else
            {
                dgvShiYan.CurrentCell = dgvShiYan[dgvShiYan.CurrentCell.ColumnIndex, 0];
            }
        }
        //上一条
        private void btn_UpItem_Click(object sender, EventArgs e)
        {
            if (dgvShiYan.CurrentCell.RowIndex > 0)
            {
                dgvShiYan.CurrentCell = dgvShiYan[dgvShiYan.CurrentCell.ColumnIndex, dgvShiYan.CurrentCell.RowIndex - 1];
            }
            else
            {
                MessageBox.Show("已到达首行!");
            }
        }
        //下一条
        private void btn_NextItem_Click(object sender, EventArgs e)
        {
            if (dgvShiYan.CurrentCell.RowIndex < dgvShiYan.RowCount - 1)
            {
                dgvShiYan.CurrentCell = dgvShiYan
                    [dgvShiYan.CurrentCell.ColumnIndex, dgvShiYan.CurrentCell.RowIndex + 1];
            }
            else
            {
                MessageBox.Show("已到达尾行!");
            }
        }
        //尾条
        private void btn_TailPage_Click(object sender, EventArgs e)
        {
            if (dgvShiYan.CurrentCell == dgvShiYan
                [dgvShiYan.CurrentCell.ColumnIndex, dgvShiYan.RowCount - 1])
            {
                MessageBox.Show("已到达尾行!");
            }
            else
            {
                dgvShiYan.CurrentCell = dgvShiYan
                [dgvShiYan.CurrentCell.ColumnIndex, dgvShiYan.RowCount - 1];
            }
        }
    }
}

猜你喜欢

转载自blog.csdn.net/qq_41890694/article/details/87724398