跳过时如何验证DataGridView行中的单元格 [英] How to validate a cell within a DataGridView Row When it's Skipped

查看:120
本文介绍了跳过时如何验证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行中的单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆