Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6096267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:54:28+00:00 2026-05-23T12:54:28+00:00

i am doing a project on window form in c# i have a DataGridView

  • 0

i am doing a project on window form in c#
i have a DataGridView with data from the database

now i want to do editing in data GridView, and i have this column call Name, but and i want to validate so that when user edit, it will only key in alphabet, like example, in the Name column row 1 has a name call Rosy Chin, then user edit to this Rosy Ch11n …it should prompt the user say that only alphabet, i use the code below but it don’t prompt me that message…however if the user edit to this 4Rosy Chin….it will appear the prompt message…can i know where am i wrong??

private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
    if (e.RowIndex >= 0 && e.ColumnIndex >= 0)
    {
        //int indicator;
        int newInteger;

        if (e.ColumnIndex == 1)
        {
            if (dataGridView1.Rows[e.RowIndex].IsNewRow) return;
            String data = e.FormattedValue.ToString();

             String validate= @"^[a-zA-Z]";
             Regex nameAlphabet = new Regex(validate);
             String nameGridView = data;                 
             if(!(nameAlphabet.IsMatch(nameGridView )))
             {
                 e.Cancel = true;
                 MessageBox.Show(@"Name must be in Alphabet!");
             }
             else
                 return;
        }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:54:28+00:00Added an answer on May 23, 2026 at 12:54 pm

    Try to fix your RegEx:

     ^[a-zA-Z ]+$
    

    Description:

    ^ start of line
    [a-zA-Z ] any letter or space
    + one or more
    $ end of line
    

    Good RegEx sandbox.


    To not allow only s space:

    ^[A-Za-z][a-zA-Z ]+[A-Za-z]$
    

    Link to the sandbox.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm doing my html and javascript class project and i want to have a
I am a newbiest in c# and window form i am doing a project
I'm doing a C# project window service. 1st time doing it. I have managed
In my project I have a Windows Service and a WCF Service doing some
I am doing project euler question 33 and have divised a refactor to solve
Im doing a project with C# winforms. This project is composed by: alt text
Im doing this project where i need to download files through a webservice (images,
I'm doing a project in seam that requires restful URLs. I have a view
I am doing a project where I want a person to enter the name
When I 'Remove' a project from a Visual Studio solution I often want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.