XML DataGridView DirtyCells

时间:2011-01-17 20:08:39

标签: c# datagridview xmldataset

我目前有一个DataGridView绑定到从XML文件读取的DataSet。

填充DataGridView就好了;最后一列是我希望用户单击以提交对行的更改的按钮。

我能够轻松找到哪些行很脏,但是,我很难找到脏行中哪些单元本身很脏。

我遍历脏行中的每个单元格,但它们没有显示为脏。

任何想法都赞赏!

if ( this.inventoryGridView.Columns[e.ColumnIndex].Name == "itemCheckedIn" )
        {
            // Give the user a visual indicator the cells are "locked"/readonly by changing the background color
            this.inventoryGridView.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.LightGray;

            // Check if any changes have been made to the row that was checked in
            if ( this.inventoryGridView.IsCurrentRowDirty )
            {
                foreach ( DataGridViewCell dirtyBoy in this.inventoryGridView.CurrentRow.Cells )
                {
                    // Is he dirty?
                }
            }

            // No changes were made to the row that was check in; let's log the check in
            else
            {
                // Log the check in time
            }

1 个答案:

答案 0 :(得分:0)

你可以试试这个:

  1. 向gridView
  2. 添加隐藏列
  3. 在将任何值更改为行中的单元格时,绑定到javascript函数
  4. 更改值时,将单元格编号作为逗号分隔值写入隐藏列,例如:更改了1,3,5个单元格编号
  5. 然后,您可以使用隐藏列值创建一个数组,并确切知道连续更改了哪些单元格。