Click here to Skip to main content
15,917,652 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
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
Posted

1 solution

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...
XML
<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>




and this code CS :

C#
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 ....
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900