Exemple #1
0
        private void dgvList_CellValidating(object sender, System.Windows.Forms.DataGridViewCellValidatingEventArgs e)
        {
//            try
//            {
//                ChungTuXuatNccChiTietHangHoaInfo info =
//                ((ChungTuXuatNccChiTietHangHoaInfo)dgvList.CurrentRow.DataBoundItem);
//                if (dgvList.Columns[e.ColumnIndex].Name == "clSoLuongXuat")
//                {
//                    int SLMoi = Convert.ToInt32(e.FormattedValue);
//                    if (SLMoi > SLCu)
//                    {
//                        if (info.SoLuongTT < SLMoi)
//                        {
//                            e.Cancel = true;
//                            throw new InvalidOperationException("Số lượng tồn không đủ để xuất !");
//                        }
//                    }
//                }
//            }
//            catch (Exception ex)
//            {
//#if DEBUG
//                MessageBox.Show(ex.ToString(), Declare.titleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
//#else
//                MessageBox.Show(ex.Message, Declare.titleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
//#endif
//            }
        }
        private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
        {
            if (dataGridView1.Columns[e.ColumnIndex].Name == "IpColumn")
            {
                if (String.IsNullOrEmpty(e.FormattedValue.ToString()))
                {
                    dataGridView1.Rows[e.RowIndex].ErrorText = "请输入IP地址.";
                    MessageBox.Show(dataGridView1.Rows[e.RowIndex].ErrorText);
                    e.Cancel = true;
                    return;
                }
                IPAddress ip;
                if (!IPAddress.TryParse(e.FormattedValue.ToString(), out ip))
                {
                    dataGridView1.Rows[e.RowIndex].ErrorText = "请输入正确的IP地址,如192.168.1.1";
                    MessageBox.Show(dataGridView1.Rows[e.RowIndex].ErrorText);
                    e.Cancel = true;
                }
            }

            if (dataGridView1.Columns[e.ColumnIndex].Name == "SecretKeyColumn")
            {
                if (String.IsNullOrEmpty(e.FormattedValue.ToString()))
                {
                    dataGridView1.Rows[e.RowIndex].ErrorText = "请输入SecretKey.";
                    MessageBox.Show(dataGridView1.Rows[e.RowIndex].ErrorText);
                    e.Cancel = true;
                    return;
                }
            }

        }
        private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
        {
            if ((m_OldValue != null) && (!m_OldValue.Equals(e.FormattedValue))) 
                m_DataChanged = true;

            m_OldValue = null;
        }
        private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
        {
            // http://www.codeproject.com/Questions/206915/What-is-the-difference-between-DataTable-DataSet-a

            // script: error JSC1000: No implementation found for this native method, please implement [System.Windows.Forms.DataGridViewCellValidatingEventArgs.get_ColumnIndex()]
            Console.WriteLine(new { e.ColumnIndex, e.RowIndex });

            if (e.ColumnIndex == 0)
            {
                var i = 0;

                // X:\jsc.svn\examples\javascript\Test\TestIntTryParse\TestIntTryParse\Application.cs

                var value =
                    (string)e.FormattedValue;

                Console.WriteLine(new { e.ColumnIndex, e.RowIndex, value });
                var ok = int.TryParse(value, out i);

                if (ok)
                {
                    this.dataGridView1[e.ColumnIndex, e.RowIndex].Style.BackColor = Color.White;

                    return;
                }

                Console.WriteLine(new { e.ColumnIndex, e.RowIndex, value, ok });

                // { ColumnIndex = 0, RowIndex = 2, value = u, ok = false } 
                this.dataGridView1[e.ColumnIndex, e.RowIndex].Style.BackColor = Color.Yellow;
                e.Cancel = true;
            }
        }
Exemple #5
0
        protected override void OnCellValidating(System.Windows.Forms.DataGridViewCellValidatingEventArgs e)
        {
            var col = this.Columns[e.ColumnIndex];

            if (col is ISelectColumn && !((ISelectColumn)col).FormatedValueIsValid(e.FormattedValue))
            {
                e.Cancel = true;
                if (((ISelectColumn)col).SelectFormType != null)
                {
                    var form = Activator.CreateInstance(((ISelectColumn)col).SelectFormType);
                    if (form != null)
                    {
                        DialogResult result = ((Form)form).ShowDialog();
                        if (result == DialogResult.OK)
                        {
                            if (form is ISelectForm)
                            {
                                //this.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = ((ISelectForm)form).SelectedItem;
                                DataGridViewRow    row = this.Rows[e.RowIndex];
                                PropertyDescriptor pd  = TypeDescriptor.GetProperties(row.DataBoundItem)[col.DataPropertyName];
                                if (pd != null)
                                {
                                    pd.SetValue(row.DataBoundItem, ((ISelectForm)form).SelectedItem);
                                }
                            }
                        }
                    }
                }
            }
            base.OnCellValidating(e);
        }
Exemple #6
0
        private void dataGridViewSk_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
        {
            try
            {
                if (String.IsNullOrEmpty(e.FormattedValue.ToString()))
                    return;
                if (dataGridViewSk.Rows[e.RowIndex].IsNewRow || e.ColumnIndex < 4)
                    return;

                var value = e.FormattedValue.ToString();
                int number;
                bool result = Int32.TryParse(value, out number);
                if (result)
                {
                    // Alt er OK!
                    Log.d("Endret krav til " + number);
                }
                else
                {
                    // Format feil!
                    if (value == null) value = "";
                    dataGridViewSk.Rows[e.RowIndex].ErrorText = "Feil format i krav. Må være hele ikke-negative tall."; //error massage
                    Log.n("Feil format i krav. Må være hele ikke-negative tall.", Color.Red);
                    e.Cancel = true;
                }
            }
            catch (Exception ex)
            {
                Log.Unhandled(ex);
                dataGridViewSk[e.ColumnIndex, e.RowIndex].Value = "0";
            }
        }
Exemple #7
0
 private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
 {
     switch (e.ColumnIndex)
     {
         case 1:
             {
                 int i;
                 if (int.TryParse(e.FormattedValue.ToString(), out i))
                     if (i < 0)
                     {
                         e.Cancel = true;
                         dataGridView1.Rows[e.RowIndex].ErrorText = "开始时间必须是非负数";
                     }
             }
             break;
         case 2:
             {
                 int i;
                 if (int.TryParse(e.FormattedValue.ToString(), out i))
                     if (i <= 0)
                     {
                         e.Cancel = true;
                         dataGridView1.Rows[e.RowIndex].ErrorText = "运行时间必须是正数";
                     }
             }
             break;
         default:
             break;
     }
 }
        private void dataGridViewDetail_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
        {
            if (e.FormattedValue == null || e.FormattedValue.ToString().Length == 0)
                return;

            switch (e.ColumnIndex)
            {
                case 0:
                    string code = e.FormattedValue.ToString();
                    Tool t = SystemHelper.TMSContext.Tools.FirstOrDefault(s => s.Code == code);
                    if (t == null)
                    {
                        e.Cancel = true;
                    }
                    else
                    {
                        dataGridViewDetail.Rows[e.RowIndex].Cells["ItemName"].Value = t.Name;
                        dataGridViewDetail.Rows[e.RowIndex].Cells["ItemDimensions"].Value = t.Dimensions;
                    }
                    break;
                case 1:
                    decimal quantity = 0;
                    if (!decimal.TryParse(e.FormattedValue.ToString(), out quantity))
                        e.Cancel = true;
                    break;

            }
        }
Exemple #9
0
 protected virtual void GRD_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
 {
     if (GRD.IsCurrentCellDirty)
     {                
         m_GanttControl.HistorySetUndoPoint();
     }
 }
Exemple #10
0
        private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
        {
            // Validate that the content length will fit into the DataSet.
            if (dataGridView1.IsCurrentCellDirty)
            {
                int maxLength = northwindDS.Tables["Customers"].Columns[e.ColumnIndex].MaxLength;

                if (e.FormattedValue.ToString().Length > maxLength)
                {
                    String error = "Column value cannot exceed " + maxLength.ToString(System.Globalization.CultureInfo.CurrentUICulture) + " characters.";

                    // Show error icon/text since the value cannot fit.
                    DataGridViewCell c = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
                    c.ErrorText = error;
                    e.Cancel = false;
                }
                else
                {
                    // Clear the error icon/text.
                    DataGridViewCell c = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
                    if (c.ErrorText != String.Empty)
                        c.ErrorText = String.Empty;
                }
            }
        }
 private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
 {
     if (int.Parse((string)e.FormattedValue) > 65535)
     {
         e.Cancel = true;
         MessageBox.Show("输入值超出限定!");
     }
 }
 private void dataGridView_CellValidating( object sender, DataGridViewCellValidatingEventArgs e )
 {
     if ( !ignoreChanges &&
         CellValidating != null )
     {
         CellValidating( this, e );
     }
 }
 private void DataGridViewCellValidating(object sender, System.Windows.Forms.DataGridViewCellValidatingEventArgs e)
 {
     if (DataGridView[e.ColumnIndex, e.RowIndex].EditType == typeof(Controls.DateControl))
     {
         Controls.DateControl control = DataGridView.EditingControl as Controls.DateControl;
         control.CheckValidation(e);
     }
 }
Exemple #14
0
        public static void ValidateRequiredGridCells(IWin32Window owner,
                                                ref DataGridView gridview,
                                                ref string msg,
                                                ref DataGridViewCellValidatingEventArgs e,
                                                bool showMessageBox)
        {
            DataGridViewRow row = gridview.Rows[e.RowIndex];

            if (row.DataGridView.IsCurrentRowDirty)
            {
                #region Validate each cell in row
                foreach (DataGridViewCell cell in row.Cells)
                {
                    bool isNotValid;
                    if (e.ColumnIndex == cell.ColumnIndex)
                    {
                        isNotValid = e.FormattedValue.Equals(string.Empty);
                    }
                    else
                    {
                        isNotValid = cell.FormattedValue.Equals(string.Empty);
                    }

                    if (isNotValid)
                    {
                        cell.ErrorText = "Can't be Empty";

                        string column = gridview.Columns[cell.ColumnIndex].HeaderText;
                        if (msg.Length == 0)
                        {
                            msg += "- " + column + ": " + cell.ErrorText;
                        }
                        else
                        {
                            msg += "\n- " + column + ": " + cell.ErrorText;
                        }
                    }
                    else
                    {
                        cell.ErrorText = string.Empty;
                    }
                }
                #endregion

                if (showMessageBox && msg.Length > 0)
                {
                    e.Cancel = true;
                    MessageBox.Show(owner, msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                foreach (DataGridViewCell cell in row.Cells)
                {
                    cell.ErrorText = String.Empty;
                }
            }
        }
Exemple #15
0
 private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
 {
     int planno = System.Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["planno_setting"].Value);
     if (planno < 0 || planno > 31)
     {
         e.Cancel = true;
         MessageBox.Show("planno 必需介於0~31之間");
     }
 }
 private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
 {
     ushort hex;
     switch (e.ColumnIndex)
     {
         case 2:
             e.Cancel = !ushort.TryParse(e.FormattedValue.ToString(), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out hex);
             break;
     }
 }
 private void dgvPodaci_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
 {
     if (dosloDoPromjene())
         switch (MessageBox.Show("Želite li pohraniti promjene?", "Informacija...", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
         {
             case DialogResult.Yes:
                 spremiPromjene();
                 break;
         }
 }
 private void gvData_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
 {
     if (e.RowIndex >= 0 && e.ColumnIndex == 3)
     {
         obj = (BindingSource)gvData.DataSource;
         SimpleData tranTemp = (SimpleData)obj.Current;
         tranTemp.Vi = e.FormattedValue.ToString();
         obj.List[e.RowIndex] = tranTemp;
     }
 }
Exemple #19
0
        public void propiedadesDataGrid_CellValidating(Object sender, DataGridViewCellValidatingEventArgs e)
        {
            if (propiedadesDataGrid.Columns[e.ColumnIndex].Name == "value")
            {
                string key = (string)propiedadesDataGrid.Rows[e.RowIndex].Cells["key"].Value;
                string value = (string)e.FormattedValue;
                aisObjectSelected.SetPropiedad(key, value);

                ActualizeTreeView();
            }
        }
Exemple #20
0
 private void stringListEditor1_CellValidating( object sender, DataGridViewCellValidatingEventArgs e )
 {
     e.Cancel = !boundFile.CharMap.ValidateString( e.FormattedValue.ToString() );
     if ( e.Cancel )
     {
         errorLabel.Text = boundFile.CharMap.LastError;
         errorLabel.Visible = true;
     }
     else
     {
         errorLabel.Visible = false;
     }
 }
        private void gridClasses_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
        {
            // Only if the Class name is being edited
              if (gridClasses.Columns[e.ColumnIndex].DataPropertyName != "fldName")
            return;

              string className = string.Format("{0}", e.FormattedValue).Trim();
              if (className.Length == 0) {
            gridClasses.Rows[e.RowIndex].ErrorText = "Class name is required.";
            e.Cancel = true;

              }
        }
Exemple #22
0
 private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
 {
     //numbers only
     this.dataGridView1.Rows[e.RowIndex].ErrorText = "";
     double NewVal = 0;
     //empty or number, or go error
     if ( e.FormattedValue.ToString()!="" && (!double.TryParse(e.FormattedValue.ToString(), out NewVal) || NewVal < 0))
     {
         e.Cancel = true;
         this.dataGridView1.Rows[e.RowIndex].ErrorText = "只能输入数字";
         return;
     }
 }
Exemple #23
0
 private void itemGrid_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
 {
     string colName = itemGrid.Columns[e.ColumnIndex].Name;
     if (colName == "dgvScale") {
         object o = e.FormattedValue;
         var d = Convert.ToDouble(o);
         if (d <= 0 || d > 100) {
             MessageBox.Show("Scale has to be greater than zero and less than 100, more or less.", "Whoops!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             e.Cancel = true;
             itemGrid.CancelEdit();
         }
     }
 }
        private void grdParameters_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
        {
            DataGridViewComboBoxCell cell = grdParameters.CurrentCell as DataGridViewComboBoxCell;

            if (cell != null && !cell.Items.Contains(e.FormattedValue))
            {
                cell.Items.Insert(0, e.FormattedValue);
                if (grdParameters.IsCurrentCellDirty)
                {
                    grdParameters.CommitEdit(DataGridViewDataErrorContexts.Commit);
                }
                cell.Value = cell.Items[0];
            }
        }
Exemple #25
0
 private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
 {
     if (e.ColumnIndex == 1)//验证指定列
     {
         float result = 0;//定义值类型变量并赋值
         if (!float.TryParse(//判断数据是否为数值类型
             e.FormattedValue.ToString(), out result))
         {
             dgv_Message.Rows[e.RowIndex].ErrorText =//提示错误信息
                 "内容必需为数值类型";
             e.Cancel = true;//取消事件的值
         }
     }
 }
        /// <param name="e">A <see cref="T:System.Windows.Forms.DataGridViewCellValidatingEventArgs"></see> that contains the event data.</param>
        protected override void OnCellValidating(System.Windows.Forms.DataGridViewCellValidatingEventArgs e)
        {
            int i, j;

            j = _Properties.ValidationTable.Rows.Count - 1;
            if (j != -1)
            {
                i = 0;
                bool check = false;
                System.Data.DataView dv = new System.Data.DataView(_Properties.ValidationTable, "Name='" + this.Columns[e.ColumnIndex].Name + "'", null, System.Data.DataViewRowState.CurrentRows);
                if (dv.Count == 1)
                {
                    if ((bool)dv[0][1])
                    {
                        if (String.IsNullOrEmpty(e.FormattedValue.ToString()))
                        {
                            this.Rows[e.RowIndex].ErrorText = "Empty Text";
                            e.Cancel = true;
                        }
                    }
                    if ((dv[0][2].ToString()) != String.Empty)
                    {
                        switch (dv[0][2].ToString())
                        {
                        case "0":
                            check = IsNumericInt(e.FormattedValue.ToString());
                            break;

                        case "1":
                            check = IsNumericDouble(e.FormattedValue.ToString());
                            break;

                        case "2":
                            check = IsEmail(e.FormattedValue.ToString());
                            break;

                        case "3":
                            check = IsDate(e.FormattedValue.ToString());
                            break;
                        }
                        if (check)
                        {
                            this.Rows[e.RowIndex].ErrorText = dv[0][3].ToString();
                            e.Cancel = check;
                        }
                    }
                }
            }
            base.OnCellValidating(e);
        }
Exemple #27
0
        private void grvDSMucTieu_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
        {
            //if (e.ColumnIndex == 2 || e.ColumnIndex == 3)
            //{
            //    grvSurvey.Rows[e.RowIndex].ErrorText = "";
            //    int newInteger;
            //    if (!int.TryParse(e.FormattedValue.ToString(), out newInteger) || newInteger < 0)
            //    {
            //        e.Cancel = true;
            //        grvSurvey.Rows[e.RowIndex].ErrorText = "Phải nhập số lớn hơn 0";
            //    }

            //}
        }
Exemple #28
0
 private void dataGridViewSolution_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
 {
     if (e.ColumnIndex == dataGridViewSolution.Columns.IndexOf(ColumnName)
         || e.ColumnIndex == dataGridViewSolution.Columns.IndexOf(ColumnText)
         || e.ColumnIndex == dataGridViewSolution.Columns.IndexOf(ColumnIP)
         || e.ColumnIndex == dataGridViewSolution.Columns.IndexOf(ColumnPort))
     {
         if (e.FormattedValue == null || e.FormattedValue.ToString().Trim().Length == 0)
         {
             MessageBox.Show(this, string.Format("{0} of solution could not be empty", dataGridViewSolution.Columns[e.ColumnIndex].HeaderText)
                 , "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             e.Cancel = true;
         }
     }
 }
Exemple #29
0
        private void dataGridViewPedidos_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
        {
            if (dataGridViewPedidos.DataSource == null)
                return;

            if (e.ColumnIndex == dataGridViewPedidos.Columns["Valor"].Index)
            {
                double valor = 0;

                if (!Double.TryParse(Convert.ToString(e.FormattedValue).Replace("R$","").Trim(), out valor))
                {
                    e.Cancel = true;
                    MessageBox.Show("Valor inválido!", "Atenção!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Exemple #30
0
        private void dataGridViewDetail_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
        {
            if (e.FormattedValue == null || e.FormattedValue.ToString().Length == 0)
                return;

            switch (e.ColumnIndex)
            {
                case 5:
                case 6:
                case 7:
                    decimal quantity = 0;
                    if (!decimal.TryParse(e.FormattedValue.ToString(), out quantity))
                        e.Cancel = true;
                    break;

            }
        }
Exemple #31
0
 private void dgvClutterLoss_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
 {
     if (((e.ColumnIndex == this.dgvClutterLoss.Columns["losses(dB)"].Index) || (e.ColumnIndex == this.dgvClutterLoss.Columns["clearance(m)"].Index)) || (e.ColumnIndex == this.dgvClutterLoss.Columns[" rx height(m)"].Index))
     {
         this.dgvClutterLoss.Rows[e.RowIndex].ErrorText = "";
         float result = 0f;
         if (!(float.TryParse(e.FormattedValue.ToString(), out result) || (e.ColumnIndex != this.dgvClutterLoss.Columns["losses(dB)"].Index)))
         {
             e.Cancel = true;
             this.dgvClutterLoss.Rows[e.RowIndex].ErrorText = PropagationResource.PROP_INPUT_NUMBER;
         }
         else if (((e.ColumnIndex == this.dgvClutterLoss.Columns["clearance(m)"].Index) || (e.ColumnIndex == this.dgvClutterLoss.Columns[" rx height(m)"].Index)) && (!float.TryParse(e.FormattedValue.ToString(), out result) || (result < 0f)))
         {
             e.Cancel = true;
             MessageBoxUtil.ShowError(PropagationResource.PROP_CLEAR_POSITIVE);
         }
     }
 }
 private void abonnementsDataGridView_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
 {
     var datagridview = (DataGridView)sender;
     var selectedCell = datagridview.SelectedCells[0];
     switch (selectedCell.ColumnIndex)
     {
         //TextOnly
         case 2:
             Validation.DataGridTextBoxValideTextSeulement(selectedCell, Resources.NomNonValide, e);
             break;
         case 3:
             Validation.DataGridTextBoxValideTextSeulement(selectedCell, Resources.PrenomNonValide, e);
             break;
         //Non vide
         case 6:
             Validation.DataGridTextBoxValideNonVide(selectedCell, Resources.NoCiviqueNonValide, e);
             break;
         case 7:
             Validation.DataGridTextBoxValideNonVide(selectedCell, Resources.RueNonValide, e);
             break;
         case 8:
             Validation.DataGridTextBoxValideNonVide(selectedCell, Resources.VilleNonValide, e);
             break;
         case 15:
             Validation.DataGridTextBoxValideNonVide(selectedCell, Resources.RemarquesNonValide, e);
             break;
         //Code postal
         case 10:
             Validation.DataGridTextBoxValideCodePostal(selectedCell, Resources.CodePostalNonValide, e);
             break;
         //Tel
         case 11:
             Validation.DataGridTextBoxValideTel(selectedCell, Resources.TelNonValide, e);
             break;
         //Cel
         case 12:
             Validation.DataGridTextBoxValideTelOpt(selectedCell, Resources.CelNonValide, e);
             break;
         //Courriel
         case 13:
             Validation.DataGridTextBoxValideEmail(selectedCell, Resources.CourrielNonValide, e);
             break;
     }
 }
Exemple #33
0
 private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
 {
     string s;
     DataGridViewRow row = dataGridView1.Rows[e.RowIndex];
     object value = e.FormattedValue;
     e.Cancel = false;
     row.ErrorText = "";
     if (row.IsNewRow) return;
     if (e.ColumnIndex == 0)
     {
         int v;
         if( (value is DBNull) || string.IsNullOrEmpty( value.ToString() ) )
         {
             e.Cancel = true;
             row.ErrorText = "The field unit_id is required";
             return;
         }
         s = value.ToString();
         if( !int.TryParse( s, out v ) )
         {
             e.Cancel = true;
             row.ErrorText = "The field unit_id must be int.";
             return;
         }
     }
     if (e.ColumnIndex == 1)
     {
         if( (value is DBNull) || string.IsNullOrEmpty( value.ToString() ) )
         {
             e.Cancel = true;
             row.ErrorText = "The field unit_name is required";
             return;
         }
     }
     if (e.ColumnIndex == 2)
     {
         if( (value is DBNull) || string.IsNullOrEmpty( value.ToString() ) )
         {
             e.Cancel = true;
             row.ErrorText = "The field unit_shortname is required";
             return;
         }
     }
 }
 private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
 {
     if (e.ColumnIndex != 1)
         return;
     var value = (string) e.FormattedValue;
     if (string.IsNullOrWhiteSpace(value))
         return;
     var oRegName = dlg.RegisterGrid[0, e.RowIndex].Value;
     RegisterStorage reg;
     if (!dlg.Architecture.TryGetRegister((string)oRegName, out reg))
         return;
     var pattern = string.Format(@"\*|([0-9a-f]{0}1,{1}{2})",
         "{",
         reg.DataType.Size * 2,
         "}");
     var re = new Regex(pattern);
     if (!re.IsMatch(value))
         e.Cancel = true;
 }
Exemple #35
0
        private void DataGridView1_CellValidating(object sender, System.Windows.Forms.DataGridViewCellValidatingEventArgs e)
        {
            if (e.ColumnIndex == 4)
            {
                if ((bool)e.FormattedValue)
                {
                    locks.Add(((Item[])dataGridView1.DataSource)[e.RowIndex]);
                }
                else
                {
                    locks.Remove(((Item[])dataGridView1.DataSource)[e.RowIndex]);
                }
            }
            if (e.ColumnIndex < 3 && ((Item[])dataGridView1.DataSource)[e.RowIndex].locked == false)
            {
                var item = ((Item[])dataGridView1.DataSource)[e.RowIndex];
                ProcessIO.WriteInt32(handle, item.address, item.id);
                ProcessIO.WriteInt32(handle, item.address + 4, item.count);
            }

            return;
        }
Exemple #36
0
        private void dataGridView1_CellValidating(object sender, System.Windows.Forms.DataGridViewCellValidatingEventArgs e)
        {
            try
            {
                if (e.RowIndex > -1)
                {
                    if (dataGridView1.Rows[e.RowIndex].IsNewRow)
                    {
                        return;
                    }

                    /*else if (dataGridView1.Columns[e.ColumnIndex] is common.DataGridViewNumericUpDownColumn &&
                     *  e.FormattedValue != null)
                     * {
                     *  decimal dec = 0.0m;
                     *  decimal.TryParse(e.FormattedValue.ToString(), out dec);
                     *  dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = dec;
                     * }*/

                    else if (dataGridView1.Columns[e.ColumnIndex] is DataGridViewTextBoxColumn &&
                             e.FormattedValue != null)
                    {
                        string cellval    = e.FormattedValue.ToString();
                        char   firstChar  = cellval.ToCharArray()[0];
                        bool   isValidStr = true;//!char.IsNumber(firstChar); //artist uses digits for the start of var and game doesn't care!!!

                        switch (firstChar)
                        {
                        case '~':
                        case '!':
                        case '@':
                        case '#':
                        case '$':
                        case '%':
                        case '^':
                        case '&':
                        case '*':
                        case '(':
                        case ')':
                        case '-':
                        case '+':
                        case '=':
                        case ',':
                        case '.':
                        case '<':
                        case '>':
                            //case ';':
                            isValidStr = false;
                            break;
                        }

                        if (!isValidStr)
                        {
                            MessageBox.Show("The value entered in \"Triggerbits\" is not a valid string");
                            e.Cancel = true;
                            dataGridView1.Rows[e.RowIndex].ErrorText = "the value must be a non-negative integer";
                        }
                        else
                        {
                            e.Cancel = false;
                            dataGridView1.Rows[e.RowIndex].ErrorText = null;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //MessageBox.Show(string.Format("row {0}, col {1}\r\nerror: {2}",e.RowIndex, e.ColumnIndex, ex.Message));
            }
        }