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

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

本文介绍了跳过时如何验证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

推荐答案

<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行中的单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 21:39