我想遍历datagridview,如果现在datagridview有四行数据,我修改了其中的三行,如何把握修改的这三行存在数组中,没修改的就不存呢?

解决方案 »

  1.   

    dataGridView1.Rows[0].State用这个属性可判断行是否修改过
      

  2.   

    找到cellvaluechanged事件就可以知道你修改了哪一行。e.RowId就是行号。
      

  3.   

     private void btnSinProduct_Click(object sender, EventArgs e)
            {
                CPRealNum1 = new string[GVCKProduct.Rows.Count, 2];
                for (int i = 0; i < GVCKProduct.Rows.Count; i++)
                {
                    if (RowIndex > -1)
                    {
                        GVCKProduct.Rows[i].Cells["RealNum"].ReadOnly = false;
                        CPRealNum1[i, 0] = GVCKProduct.Rows[i].Cells["PTCode"].Value.ToString();
                        CPRealNum1[i, 1] = GVCKProduct.Rows[i].Cells["RealNum"].Value.ToString();                    this.GVCKProduct.CurrentCell = GVCKProduct.Rows[RowIndex].Cells["RealNum"]; //设置当前单元格
                        GVCKProduct.BeginEdit(true);
                        GVCKProduct.CommitEdit(DataGridViewDataErrorContexts.Commit);
                        
                    }
                    else
                    {
                       MessageBox.Show("请选择要盘点的物料!", "系统提示");
                    }
            }
    这是我的代码,我想我点击修改了哪一行,就把哪行的数据存起来,可是我的代码总是不对,请帮我看看,先谢谢了