![](/img/trans.png)
[英]How do I refresh my datagrid view from another form after I insert and update my values inside my database?
[英]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.