private void btn_Save_Click(object sender, EventArgs e) { try { IRowBuffer myRowBuffer = this.dgv_FieldValue.Tag as IRowBuffer; for (int i = 0; i < this.dgv_FieldValue.Rows.Count; i++) { DataGridViewRow myViewRow = this.dgv_FieldValue.Rows[i]; if (myViewRow.Tag == null) { continue; } EditField editfield = myViewRow.Tag as EditField; if (myViewRow.Cells["fieldvalue"].Value == null || string.IsNullOrEmpty(myViewRow.Cells["fieldvalue"].Value.ToString())) { if (editfield.fieldInfo.Nullable) { myRowBuffer.SetNull(editfield.fieldIndex); } } else { IDomain dm = editfield.fieldInfo.Domain; if (dm == null || dm.DomainType == gviDomainType.gviDomainRange) { myRowBuffer.SetValue(editfield.fieldIndex, myViewRow.Cells["fieldvalue"].Value); } else { myRowBuffer.SetValue(editfield.fieldIndex, this.GetDomainNameValuePair(dm)[myViewRow.Cells["fieldvalue"].Value.ToString()]); } } } fc.Store(myRowBuffer); MessageBox.Show("保存编辑成功!"); (this.Owner as MainForm).UnhighlightRcFeature(fc, fid); this.Close(); } catch { MessageBox.Show("保存编辑失败!"); } }
private void dgv_FieldValue_CellValueChanged(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0) { DataGridViewRow myViewRow = this.dgv_FieldValue.CurrentRow; if (myViewRow == null) { return; } if (e.ColumnIndex == myViewRow.Cells["fieldvalue"].ColumnIndex) { object oRowTag = myViewRow.Tag; if (oRowTag == null) { return; } EditField ef = oRowTag as EditField; IFieldInfo myField = ef.fieldInfo; IDomain fieldDomain = myField.Domain; if (fieldDomain == null || fieldDomain.DomainType != gviDomainType.gviDomainRange || myViewRow.Cells[e.ColumnIndex].Value == null) { return; } IRangeDomain rdm = fieldDomain as IRangeDomain; decimal minValue = decimal.Parse(rdm.MinValue.ToString(), NumberStyles.Any); decimal maxValue = decimal.Parse(rdm.MaxValue.ToString(), NumberStyles.Any); decimal newValue = decimal.Parse(myViewRow.Cells[e.ColumnIndex].Value.ToString(), NumberStyles.Any); if (newValue < minValue || newValue > maxValue) { MessageBox.Show("值超出域范围!"); myViewRow.Cells[e.ColumnIndex].Value = (this.dgv_FieldValue.Tag as IRowBuffer).GetValue(ef.fieldIndex); } } } }