跳过时如何验证DataGridView行中的单元格

编程入门 行业动态 更新时间:2024-10-27 17:09:23
本文介绍了跳过时如何验证DataGridView行中的单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个在行中有6个单元格的DataGridView.我尝试使用CellValidating事件在输入单元格时对其进行编辑.除非用户通过在第一个单元格中输入数据然后单击(例如)第五个单元格来跳过某些单元格,否则这将很好地工作.我尝试使用RowValidated事件返回并验证所有单元格,但它不支持e.cancel语句.任何帮助,将不胜感激.谢谢,Eddie

I have a DataGridView with 6 cells in the row. I tried using the CellValidating event to edit the cells as they''re entered. This works fine unless the user skips some cells by entering data in the first cell then clicking on, say, the fifth cell. I tried using the RowValidated event to go back and validate all the cells, but it doesn''t support the e.cancel statement. Any help would be appreciated. Thanks, Eddie

推荐答案

hi 我帮你 但如果您听不懂我的英语不好,请告诉我 现在 看起来我有一个单元格的datagridview 但是数据必须在此单元格条件下 客户名称只能包含拉丁字母和空格,并且必须以字母开头." 代码Xaml这样:但是糟糕,我使用telerik sory ... hi i help you but i am not good in english if you don''t understand pls tell me now look i have datagridview with one cell But the data must be in this cell conditions "The name of the customer may contain only Latin letters and empty spaces and must start with a letter." code Xaml this: but oops i use telerik sory... <telerik:RadGridView CellValidating="RadGridView1_CellValidating" Name="RadGridView1" CanUserFreezeColumns="False" ItemsSource="{Binding Customers}" AutoGenerateColumns="False" ActionOnLostFocus="CommitEdit" RowIndicatorVisibility="Visible"> <telerik:RadGridView.Columns> <telerik:GridViewDataColumn DataMemberBinding="{Binding ContactName}" Header="Contact Name *" /> </telerik:RadGridView>

和此代码CS:

and this code CS :

using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text.RegularExpressions; using System.Windows.Controls; using System.Windows.Media; using Telerik.Windows.Controls.GridView; using Telerik.Windows.Controls.GridView.Cells; using ValidationResult=Telerik.Windows.Controls.GridView.ValidationResult; using Telerik.Windows.Controls; namespace GridView.Validation { public partial class Example { private List<string> allCountries; public Example() { InitializeComponent(); } public void RadGridView1_CellValidating(object sender, GridViewCellValidatingEventArgs e) { bool isValid = true; string validationText = "Validation failed. "; GridViewCell cell = e.Cell; isValid = ValidateName((string) e.NewValue); if (!isValid) { validationText += "The name of the customer may contain only Latin letters" + Environment.NewLine + "and empty spaces and must start with a letter."; } } private static bool ValidateName(string name) { if (name == null) { return false; } return Regex.IsMatch(name, @"^([A-Za-z]+\s*)+

"); } "); }

我使用正则表达式........,但是使用正则表达式时必须放置此

i user Regex ........ but you must put this when you use Regex

using System.Text.RegularExpressions;

结束 如果我帮助您,请告诉我....

end if i help you pls tell me ....

更多推荐

跳过时如何验证DataGridView行中的单元格

本文发布于:2023-11-24 10:10:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1624784.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:跳过   单元格   DataGridView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!