Click here to Skip to main content
14,732,982 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a datagrid view which retrieve data from MS ACCESS database.and one of the column is Date/Time type. i retrieve this column in datagridview using the following code


dataGridView1.Columns["DATERECEIVED"].DefaultCellStyle.Format = "yyyy-MM-dd HH:mm:ss";


I use the following eventhandler too

 private void dataGridView1_DataError(object sender, DataGridViewDataErrorEventArgs anError)
        {
            if (anError.Exception != null && anError.Context == DataGridViewDataErrorContexts.Commit)
            {

                MessageBox.Show("Error : " + anError.Context.ToString());
                anError.Cancel = true;
            } 
}



the problem is that whenever I type or attempt to type first digit in the cell of the column DATERECEIVED it raise the Dataerror event and shows the message Error:Commit. when I click the messageBox button OK it allows me to continue further editing. how I can get rid of this problem. please somebody help me
Posted
Updated 13-Oct-11 7:35am
v2

1 solution

You could raise a 'dataGridView1_CellEndEdit' event, and then check, using IsDate, if the date entered is valid.
   

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