[英]DataGridView Save Changes On Row Change
我想在將行留在DataGridView
后保存記錄。
我已經看到解決方案使用RowValidated
事件,但是,當行被排序時,在觸發RowValidation
事件之前,記錄將被使用。 我還嘗試使用BindingSource
Current屬性獲取行,但當前屬性已更改。 同樣適用於RowLeaving我相信。
我已經嘗試直接在數據表上使用RowChanged
事件,這確實有效。
我最終使用RowValidation
事件並從數據表中獲取更改( GetChange())
,但這似乎不太明白。
除了刪除我使用了UserDeletingRow
事件,但這似乎不是想法。
離開行后保存記錄的最佳方法是什么?
你看過.RowLeave
嗎?
private void dataGridView1_RowEnter(object sender,
DataGridViewCellEventArgs e)
{
for (int i = 0; i < dataGridView1.Rows[e.RowIndex].Cells.Count; i++)
{
dataGridView1[i, e.RowIndex].Style.BackColor = Color.Yellow;
}
}
private void dataGridView1_RowLeave(object sender,
DataGridViewCellEventArgs e)
{
for (int i = 0; i < dataGridView1.Rows[e.RowIndex].Cells.Count; i++)
{
dataGridView1[i, e.RowIndex].Style.BackColor = Color.Empty;
}
}
來源: http : //msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.rowleave.aspx
您是否嘗試過DataGridView.RowValidating Event
和.IsCurrentRowDirty
?
private void dataGridView1_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
{
if (dataGridView1.IsCurrentRowDirty)
{
//Do stuff
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.