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 6014635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:43:14+00:00 2026-05-23T02:43:14+00:00

Lets simplify. Lets say I have this class: class Foo { public string Name

  • 0

Lets simplify. Lets say I have this class:

class Foo
{
    public string Name { get; set; }
    public int Age { get; set; }
    public int height{ get; set; }
    ...
}

and I have a DataGridView.DataSource bound to a BindingList<Foo> with N columns, each one bound to each property.

I need to:

  • Allow the user to enter non validating ages, heights, etc (for instance “aaa”)
  • Color the cells with non validating values (red background)
  • Retain the non validating values displayed until the form is closed (I don’t want to lose the values entered until the form is closed, so the user has the option to correct the bad cells anytime he wants BEFORE closing the form)
  • Keep the last correct values entered for each cell with non validating values entered.
  • When the form is closed, ditch the non validating values and keep the last correct values entered.

Is there any easy way to do this?

  • 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-23T02:43:15+00:00Added an answer on May 23, 2026 at 2:43 am

    I’ve got same problem with date column yesterday.

    I’ve found CellFormatting and CellParsing events, but BindingSource seems to ignore them. So I did it like this. I’ve used cell. Tag property. dgv is DataGridView here.

      private void dgv_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            if (IsBirthdayColumn(e.ColumnIndex))
            {
                e.Value = dgv[e.ColumnIndex, e.RowIndex].Tag;
                if (e.Value is DateTime)
                {
                    e.Value = ((DateTime)e.Value).ToShortDateString();
                }
                e.FormattingApplied = true;
            }
        }
    
        private void dgv_CellParsing(object sender, DataGridViewCellParsingEventArgs e)
        {
            DateTime date;
            if (IsBirthdayColumn(e.ColumnIndex))
            {
                if (e.Value != null && DateTime.TryParse(e.Value.ToString(), out date))
                {
                    e.Value = date;
                    dgv[e.ColumnIndex, e.RowIndex].Tag = e.Value;
                }
                else
                {
                    dgv[e.ColumnIndex, e.RowIndex].Tag = e.Value;
                    e.Value = DBNull.Value;
                }
                e.ParsingApplied = true;
            }
        }
    
       private void dgv_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
        {
            DateTime date;
            if (IsBirthdayColumn(e.ColumnIndex))
            {
                var cell = dgv[e.ColumnIndex, e.RowIndex];
                if (e.FormattedValue != null && !DateTime.TryParse(e.FormattedValue.ToString(), out date))
                {
                    if (e.FormattedValue.ToString().Trim().Equals(""))
                    {
                        cell.ErrorText = string.Empty;
                        return;
                    }
                    cell.ErrorText = "Invalid date format";
                }
                else
                {
                    cell.ErrorText = string.Empty;
                }
            }
        }
    

    Also u need to handle DataError event

        private void dgv_DataError(object sender, DataGridViewDataErrorEventArgs e)
        {
            ......
            e.Cancel = false;
            ......
        }
    

    Now u can write anything in date column. In the case of invalid date it will show u error icon and save DBNull in DataSet. In the case of empty string it will just save DBNull.

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

Sidebar

Related Questions

Lets say I have the following code: abstract class Animal case class Dog(name:String) extends
lets say I have class : foo { public: static const foo Invalidfoo; foo();
Lets say I have a Dictionary object: Dictionary myDictionary<int, SomeObject> = new Dictionary<string, SomeObject>();
Lets say I have an array like this: string [] Filelist = ... I
I'm gonna try and simplify this as much as possible. Lets say i have
Lets say i have a form which have the following : Name:TextBox Email:TextBox Age:TextBox
Lets say I have a String: Go to this page: http://mysite.com/?page=1 , and I
Let's say we have two functions: int f(); int g(); I want to get
Let's say I have following ORM classes (fields removed to simplify): class Animal(models.Model): say
Lets say I have this XML: <images> <photo> <thumbImg>images/thumbs/002.jpg</thumbImg> <filename>002</filename> </photo> <photo> <thumbImg>images/thumbs/008.jpg</thumbImg> <filename>008</filename>

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.