关键代码:this.dataGridView1.CurrentCell = this.dataGridView1.Rows[number].Cells[0];
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void 生成数据ToolStripMenuItem_Click(object sender, EventArgs e)
{
List
for (int index = 0; index < 9999; index++)
{
var model = new TestModel();
model.A1 = "A1:" + index;
model.A2 = "A2:" + index;
model.A3 = "A3:" + index;
lst.Add(model);
}
this.dataGridView1.DataSource = lst;
}
private void 冻结ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.dataGridView1.Enabled = false;
}
private void 解冻ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.dataGridView1.Enabled = true;
}
private void 跳转到指定行ToolStripMenuItem_Click(object sender, EventArgs e)
{
FrmNumber fm = new FrmNumber();
fm.ShowDialog();
int number = fm.number;
if (this.dataGridView1.Rows.Count == 0)
{
return;
}
this.dataGridView1.CurrentCell = this.dataGridView1.Rows[number].Cells[0];
}
}
}
namespace WindowsFormsApp1
{
public partial class FrmNumber : Form
{
public int number = 0;
public FrmNumber()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
this.number = Convert.ToInt32(this.textBox1.Text.Trim());
this.Close();
}
}
}