本人是个初学者,经常有很多问题解决不了,今天就为了DATAGRIDVIEW的记录指针上移下移而走遍了百度,最后也是空手而归,于是只能自己动手解决,运气还不错被我找到了,这点小知识对于高手们来说,简直太不起眼了,但对于像我这样的初学者,我想下面的内容对大家很有帮助:
\n
/// <summary>
/// 数据上移一条
/// </summary>
/// <param name=”sender”></param>
/// <param name=”e”></param>
private void tsbBack_Click(object sender, EventArgs e)
{
int i = dgvMain.Rows.GetPreviousRow(dgvMain.CurrentRow.Index, DataGridViewElementStates.None); //获取原选定上一行索引
dgvMain.Rows[i].Selected = true; //选中整行
dgvMain.CurrentCell = dgvMain[0, i]; //指针上移
}
/// <summary>
/// 数据下移一条
/// </summary>
/// <param name=”sender”></param>
/// <param name=”e”></param>
private void tsbNext_Click(object sender, EventArgs e)
{
int i = dgvMain.Rows.GetNextRow(dgvMain.CurrentRow.Index,DataGridViewElementStates.None); //获取原选定下一行索引
dgvMain.Rows[i].Selected = true; //选中整行
dgvMain.CurrentCell = dgvMain[0,i]; //指针下移
}
DGVMAIN是DATAGRIDVIEW
\n
来源:http://blog.csdn.net/xiezuojia
\n