DataSet.HasChanges
编辑一行, 焦点离开编辑的那个行, DataRow 才获知改变,或者主动调用 EndEdit.
((CurrencyManager)this.BindingContext[dgvSysPara.DataSource]).EndCurrentEdit();
如何判断dataGridView内单元格是否被编辑过,DataGridView 有个捕获Cell值已更改的事件CellValueChanged 应该可以
问题已解决,在更改值的时候会触发这个事件,我在这个事件中通过改变一个全局变量的值来标识值是否已经被改变
private void grd_CurrentCellDirtyStateChanged(object sender, EventArgs e)
{
if(grd.IsCurrentCellDirty)
grd.CommitEdit(DataGridViewDataErrorContexts.Commit);
}
我感觉可以给你的表一个状态,如果编辑过就将状态改成1,否则就是0呗
private void DataGridView1_CellValueChanged(
object sender, DataGridViewCellEventArgs e)
{
// Update the balance column whenever the value of any cell changes.
UpdateBalance();
}
private void DataGridView1_RowsRemoved(
object sender, DataGridViewRowsRemovedEventArgs e)
{
// Update the balance column whenever rows are deleted.
UpdateBalance();
}
private void UpdateBalance()
{
int counter;
int balance;
int deposit;
int withdrawal;
// Iterate through the rows, skipping the Starting Balance row.
for (counter = 1; counter < (DataGridView1.Rows.Count - 1);
counter++)
{
deposit = 0;
withdrawal = 0;
balance = int.Parse(DataGridView1.Rows[counter - 1]
.Cells["Balance"].Value.ToString());
if (DataGridView1.Rows[counter].Cells["Deposits"].Value != null)
{
// Verify that the cell value is not an empty string.
if (DataGridView1.Rows[counter]
.Cells["Deposits"].Value.ToString().Length != 0)
{
deposit = int.Parse(DataGridView1.Rows[counter]
.Cells["Deposits"].Value.ToString());
}
}
if (DataGridView1.Rows[counter].Cells["Withdrawals"].Value != null)
{
if (DataGridView1.Rows[counter]
.Cells["Withdrawals"].Value.ToString().Length != 0)
{
withdrawal = int.Parse(DataGridView1.Rows[counter]
.Cells["Withdrawals"].Value.ToString());
}
}
DataGridView1.Rows[counter].Cells["Balance"].Value =
(balance + deposit + withdrawal).ToString();
}
}