2013-02-11 103 views
7

我试图在离开DataGridView中的行后保存记录。DataGridView在行更改上保存更改

我已经看到解决方案使用RowValidated事件,但是,当行被排序时,记录会在触发RowValidation事件之前采取行动。我也尝试使用BindingSource当前属性获取该行,但当前属性已更改。我相信这同样适用于RowLeaving。

我试图直接在数据表上使用RowChanged事件,并且确实工作正常。

我结束了使用RowValidation事件,并充分利用数据表(GetChange())的变化,但是这似乎并没有概念。

除了为我所用的UserDeletingRow事件删除,但这又似乎没有想法。

什么是离开行后保存记录的最佳方式?

回答

3

您拍照时看看.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

+2

在'RowLeave'期间似乎没有包含更改。 – user824911 2013-02-12 01:50:32