dataset 数据集数据发生了变化,但是,HasChanges()则返回为false。
我自我感觉是如下代码出了问题,但是不知道该怎么解决,请高手帮忙看看。
private DataGridCell editCell;
private bool inEditMode = false;
private bool inUpdateMode = false;
private void dataGrid1_CurrentCellChanged(object sender, EventArgs e)
{
if (!inUpdateMode)
{
if (inEditMode && !dataGrid1.CurrentCell.Equals(editCell))
{ // Update edited cell
UpdateTextBoxNum();
}
// Enter edit mode
if (dataGrid1.CurrentCell.ColumnNumber == 2)
{
editCell = dataGrid1.CurrentCell;
txtEdit.Text = (string)dataGrid1[editCell.RowNumber,
editCell.ColumnNumber];
txtEdit.Focus();
txtEdit.Select(0, txtEdit.Text.Length);
Rectangle cellPos = dataGrid1.GetCellBounds(editCell.RowNumber,
editCell.ColumnNumber);
txtEdit.Left = cellPos.Left;
txtEdit.Top = cellPos.Top + dataGrid1.Top;
txtEdit.Width = cellPos.Width;
txtEdit.Height = cellPos.Height;
txtEdit.Visible = true;
inEditMode = true;
}
}
}
private void UpdateTextBoxNum()
{
inUpdateMode = true;
dataGrid1.Visible = false;
DataGridCell currentCell = dataGrid1.CurrentCell;
dataGrid1[editCell.RowNumber, editCell.ColumnNumber] = txtEdit.Text;
dataGrid1.CurrentCell = currentCell;
dataGrid1.Visible = true;
inUpdateMode = false;
txtEdit.Visible = false;
inEditMode = false;
}