[英]FormClosing does not see DataGridView Rows and Columns
請問,這有什么問題:
Form2_Closing:
Form1.DataGridView1.Rows[0].Cells[1].Value = "323";
錯誤:索引超出范圍。 必須是非負數且小於集合的大小。 參數名稱:index
Form1上的DGV有10行和14列
從您的注釋中看起來您正在嘗試創建一個自定義Dialog,它將在調用表單上的DataGridView
操作特定值。 我建議在看這個創建自定義消息框的例子。
您將能夠返回說出您想要更新DataGridViewCell
的值,然后在Form1
上設置它。
創建一個新的Winforms項目並添加一個按鈕及其單擊處理程序和一個TextBox [使其可訪問,以便子項可以設置值。 我現在也在設計師中公開了。 然后在此表單上添加以下代碼。 此外,在項目中添加新表單(Form2)。
private void button1_Click(object sender, EventArgs e)
{
var child = new Form2();
child.FormClosing += new FormClosingEventHandler(ChildFormClosing);
this.Enabled = false;
child.Show(this);
}
void ChildFormClosing(object sender, FormClosingEventArgs e)
{
var child = sender as Form2;
if (child != null)
{
if (child.DialogResult == DialogResult.None)
{
// do data grid view manipulation here
// for ex:
(child.Owner as Form1).textBox1.Text = "Hi";
}
}
Enabled = true;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.