我會盡量清楚:) 由於按鈕,我正在動態創建新的DataGridView
。如何動態訪問當前DataGridView
它工作正常,但我希望能夠更改DataGridView
的一個單元格的值,並更新我的數據庫。 問題是,我沒有找到如何獲得當前重點DataGridView
。
我試着玩這個link的代碼,我得到了當前的DataGridView
的名字。 但我不認爲我可以操縱一個控件作爲DataGridView
。 這裏是我的功能:
private void dataGridView_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
DataGridView datagridcell = new DataGridView();
string codearticle = "'" + CodeArticle0.Text + "'";
string division = "'" + Division0.Text + "'";
string colonne = datagridcell.Columns[e.ColumnIndex].HeaderText;
string valeur = sender.ToString();
string Ligne = datagridcell.Rows[0].Cells[3].ToString();
Controller.ControllerMenuPrincipal.updateQALigneFab(codearticle, division,
colonne, valeur, Ligne);
}
取而代之的是:
DataGridView datagridcell = new DataGridView();
我想訪問當前/聚焦datagridview的
我不知道,如果可能的話,我是小白在winforms中。
感謝您的幫助
如果您將'dataGridView_CellValueChanged'附加到您的動態網格的'CellValueChanged',則'sende r'參數是事件爲其觸發的'DataGridView'。所以你可以通過這種方式得到發送者'DataGridView':'var grid =(DataGridView)sender;'。 –
謝謝!這正是我需要的。 –
不客氣:) –