繁体   English   中英

如何以另一种形式将我的数据网格视图项显示到文本框?

[英]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();
    
    
 }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM