private void dgData_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
        {
            DataGridViewRow row = dgData.Rows[e.RowIndex];

            if (row.IsNewRow)
            {
                return;
            }

            DataGridViewCell cell = row.Cells[e.ColumnIndex];

            string currentValue = cell.EditedFormattedValue + string.Empty;

            //TODO valid cell value
            cell.ErrorText = string.Empty;
            DataGridViewColumn column     = cell.OwningColumn;
            XmlElement         colElement = column.Tag as XmlElement;
            string             fieldName  = colElement.GetAttribute("Field");
            XmlElement         xml        = _source.GetElement("Field[@Name='" + fieldName + "']");

            if (xml == null)
            {
                return;
            }

            try
            {
                UDTTable.ValidFieldValue(xml, currentValue);
            }
            catch (Exception ex)
            {
                cell.ErrorText = ex.Message;
                //e.Cancel = true;
            }
        }
        private void dgData_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
        {
            DataGridViewRow row = dgData.Rows[e.RowIndex];

            if (row.IsNewRow)
            {
                return;
            }

            bool error = false;

            foreach (DataGridViewColumn column in dgData.Columns)
            {
                DataGridViewCell cell         = dgData.Rows[e.RowIndex].Cells[column.Index];
                string           currentValue = cell.Value + string.Empty;
                //TODO valid cell value
                cell.ErrorText = string.Empty;
                XmlElement colElement = column.Tag as XmlElement;
                string     fieldName  = colElement.GetAttribute("Field");
                XmlElement xml        = _source.GetElement("Field[@Name='" + fieldName + "']");
                if (xml == null)
                {
                    continue;
                }

                if (UDTTable.IsDefaultField(fieldName))
                {
                    continue;
                }

                try
                {
                    UDTTable.ValidFieldValue(xml, currentValue);
                }
                catch (Exception ex)
                {
                    cell.ErrorText = ex.Message;
                    error          = true;
                }
            }

            if (error)
            {
                e.Cancel = true;
            }
        }