2
我們曾經使用過一個遠端網格,這個網格很容易,但現在我們使用datagridview來處理表單。 我的問題是我需要更新記錄,因爲它在datagridview中更改,我使用了Cell Leave事件。在datagridview單元格值更改後更新數據庫記錄?
private void dataGridView1_CellLeave(object sender, DataGridViewCellEventArgs e)
{
if (dataGridView1[e.ColumnIndex, e.RowIndex].Value == null)//incase it is a blanked cell
{
MessageBox.Show("Cell changed:" + e.ColumnIndex.ToString() + ":" + e.RowIndex.ToString() + " New Value:" + " null");
}
else
{
MessageBox.Show("Cell changed:" + e.ColumnIndex.ToString() + ":" + e.RowIndex.ToString() + " New Value:" + dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString());
}
}
我通過更改值測試上面的代碼,然後按回車鍵(就像用戶目前做的),但它顯示未改變的值,但前一個。
我已經完成的解決方法是更新datagridview中的所有記錄,問題比先前我需要的時間還要多15秒 - 而且,如果僅更改一條記錄,則不需要這麼做。
謝謝你對你的這個答案的人!!! :-) – Sylca 2013-01-09 10:00:26