如何調用函數內的事件?因爲我有一個錯誤Object reference not set to instance of an object
和錯誤指出:_e.RowIndex
調用函數c中的事件#
而我想知道如何調用一個函數內的事件。現在我可以從new EventHandler(....)
調用事件,但現在我想調用一個函數內部的事件,它給我的錯誤Object reference not set to instance of an object
下面是代碼:
private void UpdateQuantityDataGridView(object sender, EventArgs e)
{
DataGridViewCellEventArgs _e = null;
cmdSelect.Parameters.Add("ProductCode" , System.Data.OleDb.OleDbType.VarChar) ;
cmdSelect.Parameters[ "ProductCode" ].Value = dataGridView1[ "Product Code" , _e.RowIndex].Value;
}
是上面的代碼中正確的方法來做到這一點?
EDITED
這是我調用的函數UpdateQuantityDataGridView
:
if (_choice.comboBox1.Text == "English")
{
System.Media.SoundPlayer _sounds = new System.Media.SoundPlayer(@"C:\Windows\Media\Windows Exclamation.wav");
_sounds.Play();
MessageBox.Show("Updated Successfully!", "Updated");
ShowButtons(sender, e);
DisableColumnEdited(sender, e);
UpdateQuantityDataGridView(sender, e);
}
這裏是我的情況:
當DataGridView的用戶編輯數據,以及用戶點擊 「確定」 按鈕,上面的代碼將執行,並從DataGridView更新數據庫,這就是爲什麼我想在函數內部訪問DataGridViewCellEventArgs
。我無法完成和工作,當我打電話通過使用new EventHandler(....)
'_e = null'引用空引用將導致'NullReferenceException'。你想要達到什麼目標?你想要什麼'_e.RowIndex'返回? –
'_e.RowIndex'是告訴程序從DataGridView中選擇了哪一行 – Kaoru
讓我看看你的代碼在哪裏調用'UpdateQuantityDataGridView' –