如何以另一种形式将我的数据网格视图项显示到文本框?
How do I display my datagrid view items to textboxes in a another form?
我正在尝试显示我的数据网格视图中的项目,但是当我单击按钮时出现错误,指出索引不能为负数,必须小于集合的大小并且超出范围。我该如何解决这个问题?
private void button2_Click(object sender, EventArgs e)
{
int row = dataGridView1.CurrentRow.Index;
Form1 f1 = new Form1();
MySqlCommand cmd = conn.CreateCommand();
VehicleEntry edit = new VehicleEntry();
edit.Show();
edit.pnumber.Text = f1.dataGridView1[0, row].Value.ToString();
}
如果此代码在 Form1 中,请删除声明新 Form 1 的行,并在最后一行使用 'this.dataGridView1[0, row].Value.ToString()'。
更改为:
private void button2_Click(object sender, EventArgs e)
{
int row = dataGridView1.CurrentRow.Index;
//Form1 f1 = new Form1(); //remove if this is Form1
MySqlCommand cmd = conn.CreateCommand();
VehicleEntry edit = new VehicleEntry();
edit.Show();
//if datagridview1 is in the current Form.
edit.pnumber.Text = this.dataGridView1[0, row].Value.ToString();
}
我正在尝试显示我的数据网格视图中的项目,但是当我单击按钮时出现错误,指出索引不能为负数,必须小于集合的大小并且超出范围。我该如何解决这个问题?
private void button2_Click(object sender, EventArgs e)
{
int row = dataGridView1.CurrentRow.Index;
Form1 f1 = new Form1();
MySqlCommand cmd = conn.CreateCommand();
VehicleEntry edit = new VehicleEntry();
edit.Show();
edit.pnumber.Text = f1.dataGridView1[0, row].Value.ToString();
}
如果此代码在 Form1 中,请删除声明新 Form 1 的行,并在最后一行使用 'this.dataGridView1[0, row].Value.ToString()'。
更改为:
private void button2_Click(object sender, EventArgs e)
{
int row = dataGridView1.CurrentRow.Index;
//Form1 f1 = new Form1(); //remove if this is Form1
MySqlCommand cmd = conn.CreateCommand();
VehicleEntry edit = new VehicleEntry();
edit.Show();
//if datagridview1 is in the current Form.
edit.pnumber.Text = this.dataGridView1[0, row].Value.ToString();
}