当前位置: 首页>>代码示例>>C#>>正文


C# Forms.DataGridViewCellValidatingEventArgs类代码示例

本文整理汇总了C#中System.Windows.Forms.DataGridViewCellValidatingEventArgs的典型用法代码示例。如果您正苦于以下问题:C# DataGridViewCellValidatingEventArgs类的具体用法?C# DataGridViewCellValidatingEventArgs怎么用?C# DataGridViewCellValidatingEventArgs使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DataGridViewCellValidatingEventArgs类属于System.Windows.Forms命名空间,在下文中一共展示了DataGridViewCellValidatingEventArgs类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: dataGridView1_CellValidating

        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;
                }
            }
        }
开发者ID:huaminglee,项目名称:DeeHome,代码行数:25,代码来源:CustomerForm.cs

示例2: dataGridView1_CellValidating

        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;
                }
            }

        }
开发者ID:helioelias,项目名称:tinyradius4net,代码行数:32,代码来源:NasClientSetting.cs

示例3: dataGridView1_CellValidating

        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;
            }
        }
开发者ID:exaphaser,项目名称:JSC-Cross-Compiler,代码行数:33,代码来源:ApplicationControl.cs

示例4: dataGridView1_CellValidating

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

            m_OldValue = null;
        }
开发者ID:Duke-Jones,项目名称:ED-IBE,代码行数:7,代码来源:EDCommodityListView.cs

示例5: GRD_CellValidating

 protected virtual void GRD_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
 {
     if (GRD.IsCurrentCellDirty)
     {                
         m_GanttControl.HistorySetUndoPoint();
     }
 }
开发者ID:Veivan,项目名称:GanttDll,代码行数:7,代码来源:ucGridView.cs

示例6: dataGridView1_CellValidating

 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;
     }
 }
开发者ID:smithLiLi,项目名称:dev,代码行数:30,代码来源:SettingDialog.cs

示例7: dataGridViewSk_CellValidating

        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";
            }
        }
开发者ID:tborgund,项目名称:kgsa,代码行数:32,代码来源:FormKrav.cs

示例8: dataGridViewDetail_CellValidating

        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;

            }
        }
开发者ID:zhangyh,项目名称:TMS,代码行数:28,代码来源:CreateOutboundOrderForm.cs

示例9: dataGridView_CellValidating

 private void dataGridView_CellValidating( object sender, DataGridViewCellValidatingEventArgs e )
 {
     if ( !ignoreChanges &&
         CellValidating != null )
     {
         CellValidating( this, e );
     }
 }
开发者ID:Wi150nZ,项目名称:lioneditor,代码行数:8,代码来源:StringListEditor.cs

示例10: dataGridView1_CellValidating

 private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
 {
     if (int.Parse((string)e.FormattedValue) > 65535)
     {
         e.Cancel = true;
         MessageBox.Show("输入值超出限定!");
     }
 }
开发者ID:bearxiong99,项目名称:DistributionLineFaultIndicator,代码行数:8,代码来源:IndtrAddrLocal.cs

示例11: ValidateRequiredGridCells

        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;
                }
            }
        }
开发者ID:emanuelshv,项目名称:tupux,代码行数:58,代码来源:Grid.cs

示例12: dataGridView1_CellValidating

 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之間");
     }
 }
开发者ID:ufjl0683,项目名称:Center,代码行数:9,代码来源:FrmRmsModeSetting.cs

示例13: gvData_CellValidating

 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;
     }
 }
开发者ID:huynhduy1985,项目名称:Joomla-translator,代码行数:10,代码来源:TranslatorOne.cs

示例14: dgvPodaci_CellValidating

 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;
         }
 }
开发者ID:hortekk,项目名称:PI_Projekt_GHIJK,代码行数:10,代码来源:frmPostavke.cs

示例15: dataGridView1_CellValidating

 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;
     }
 }
开发者ID:Ermelber,项目名称:EveryFileExplorer,代码行数:10,代码来源:KCLCollisionTypeSelector.cs


注:本文中的System.Windows.Forms.DataGridViewCellValidatingEventArgs类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。