当前位置:编程学习 > C#/ASP.NET >>

DataGridView保存行状态的问题


 private void dataGridView1_RowLeave(object sender, DataGridViewCellEventArgs e)
        {
            if (this.dataGridView1.IsCurrentRowDirty)
            {
                this.dataGridView1.EndEdit();
                this.dataGridView1.CommitEdit(DataGridViewDataErrorContexts.CurrentCellChange);
                Save(e.RowIndex);
            }
            
          
        } 
        private void Save(int rowIndex)
        {
            DataTable table = this.dataGridView1.DataSource as DataTable;
            if (table == null)
                return;
            
            //table.GetChanges();

            DataRow row = table.Rows[rowIndex];
            if (row.RowState == DataRowState.Unchanged)
                return;


这时候为什么行状态还是UnChange呀~希望大侠帮忙解决下 --------------------编程问答-------------------- 这样试下呢:
private void dataGridView1_CurrentCellDirtyStateChanged(object sender, EventArgs e)
        {
            this.dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
        }
--------------------编程问答-------------------- 还是不行  同样是UnChange!! --------------------编程问答--------------------

DataRow row = table.Rows[rowIndex];
            System.Console.WriteLine("in dataTable " + row[1]);
            System.Console.WriteLine("row.RowState = " + row.RowState);
            System.Console.WriteLine("row.version = " + row[1,DataRowVersion.Proposed]);

我在电脑上运行了以下,打印出来是Unchanged,但是被修改的那个字段的值,保存在DataRowVersion.Proposed中。
而此时DataRowVersion.Default等于DataRowVersion.Proposed。
DataRowVersion.Original和DataRowVersion.Current中保存的都是原值。

MSDN对DataRowVersion的解释:在DataRowState 等于Detached的时候,DataRowVersion.Default等于DataRowVersion.Proposed。
但此时打印出的row.RowState = Unchanged。

public enum DataRowVersion

The default version of DataRowState. For a DataRowState value of Added, Modified or Deleted, the default version is Current. For a DataRowState value of Detached, the version is Proposed.  --------------------编程问答-------------------- 加上ispostback判断一下
  --------------------编程问答-------------------- 那怎么解决这个问题列~~
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,