日期:2014-05-17  浏览次数:20950 次

DatagridView编辑事件
 private void dgvData_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            string Area = this.dgvData.Rows[e.RowIndex].Cells["Area"].Value.ToString();    //获取区域列值
            string Locate = this.dgvData.Rows[e.RowIndex].Cells["Location"].Value.ToString();  //获取位置列值

            if (Area != "" && Locate != "")   //判断都不为空
            {
                bool isNo = false;  //用于判断该区域和位置是否存在
                for (int i = 0; i < this.dgvData.Rows.Count - 2; i++)
                {
                    if (Area == dgvData.Rows[i].Cells["Area"].Value.ToString() && Locate == dgvData.Rows[i].Cells["Location"].Value.ToString())   //判断该区域和位置是否已经存在
                    {
                        isNo = true;  //已存在
                        break;
                    }
                }

                if (isNo == true)   //如果存在可选择是否覆盖
                {
                    if (MessageBox.Show("该区域中的位置已经存在!是否覆盖?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1) == DialogResult.OK)
                    {