• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Forms.DataGridViewCellValidatingEventArgs类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: propiedadesDataGrid_CellValidating

        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();
            }
        }
开发者ID:riseven,项目名称:AIStudio,代码行数:11,代码来源:AisForm.cs


示例17: itemGrid_CellValidating

 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();
         }
     }
 }
开发者ID:kfsone,项目名称:houseomatic,代码行数:13,代码来源:HouseForm.cs


示例18: stringListEditor1_CellValidating

 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;
     }
 }
开发者ID:Wi150nZ,项目名称:lioneditor,代码行数:13,代码来源:FileEditor.cs


示例19: gridClasses_CellValidating

        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;

              }
        }
开发者ID:oobayly,项目名称:LDYC-Trophies,代码行数:13,代码来源:EditClassesDialog.cs


示例20: dataGridView1_CellValidating

 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;
     }
 }
开发者ID:DawnEve,项目名称:learngit,代码行数:13,代码来源:Form1.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Forms.DataGridViewCellValueEventArgs类代码示例发布时间:2022-05-26
下一篇:
C# Forms.DataGridViewCellStyle类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap