//下移一行
private void button2_Click( object sender, EventArgs e )
{
DataGridViewRow dr = dataGridView1.CurrentRow;
if ( dr.Index < dataGridView1.Rows.Count - 1 )
{
int index = dr.Index;
dataGridView1.Rows.Remove( dr );
dataGridView1.Rows.Insert( index + 1, dr );
dr.Selected = true;
dataGridView1.CurrentCell = dr.Cells[0];
}
}
//上移一行
private void button3_Click( object sender, EventArgs e )
{
DataGridViewRow dr = dataGridView1.CurrentRow;
if ( dr.Index > 0 )
{
int index = dr.Index;
dataGridView1.Rows.Remove( dr );
dataGridView1.Rows.Insert( index - 1, dr );
dr.Selected = true;
dataGridView1.CurrentCell = dr.Cells[0];
}
}
//首行
private void button4_Click( object sender, EventArgs e )
{
if ( dataGridView1.CurrentRow.Index != 0 )
{
DataGridViewRow dr = dataGridView1.CurrentRow;
dataGridView1.Rows.Remove( dr );
dataGridView1.Rows.Insert(0, dr );
dr.Selected = true;
dataGridView1.CurrentCell = dr.Cells[0];
}
}
//末行
private void button5_Click( object sender, EventArgs e )
{
if ( dataGridView1.CurrentRow.Index <dataGridView1.Rows.Count-1 )
{
DataGridViewRow dr = dataGridView1.CurrentRow;
dataGridView1.Rows.Remove( dr );
dataGridView1.Rows.Insert( dataGridView1.Rows.Count , dr );
dr.Selected = true;
dataGridView1.CurrentCell = dr.Cells[0];
}
}