ritestato il mio codice e funziona
codice:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
for (int n = 0; n < 2; n++)
dt.Columns.Add(new DataColumn("col" + n.ToString(), typeof(System.Int16)));
for (int n = 0; n < 10; n++)
dt.Rows.Add(n, n * 10);
this.dataGridView1.DataSource = dt;
this.dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
}
private void button1_Click(object sender, EventArgs e)
{
int index = this.dataGridView1.CurrentRow.Index;
if (index == this.dataGridView1.RowCount - 1)
return;
this.dataGridView1.CurrentCell = this.dataGridView1.Rows[index + 1].Cells[0];
}
private void button2_Click(object sender, EventArgs e)
{
int index = this.dataGridView1.CurrentRow.Index;
if (index == 0)
return;
this.dataGridView1.CurrentCell = this.dataGridView1.Rows[index - 1].Cells[0];
}
}