版权声明:本文为博主原创文章,转载请附上博文链接! https://blog.csdn.net/qq_41890694/article/details/87724398
由于本人之前做C#、.NET、WCF项目是一直想要这种效果,想了许久,虽然能勉强实现,但却不是我所想要的,因此我后来也找了很多资料,最后我通过查找资料结合起来想出我想要的代码便实现我想要的功能,相信有些朋友也找这种实现,希望能帮到您。
实现截图::
实现代码::
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];
}
}
}
}