hi there,

how can i validate a data grid view column to enter only the date in the data grid view column. i am doing this in a 2008 VS C# standard edition software. how can i do this.
thankx

>how can i validate a data grid view column to enter only the date in the data grid view column.

If bounded columns. See this code-snippet.

DataTable dt=new DataTable();
dt.Columns.Add("BDate",typeof(DateTime));

dataGridView1.DataSource=dt;

hey my code for retrieving data from the grid view is below:

public void AddActions()
         {
             int countRow = dgvAList.RowCount;
             int countCol = dgvAList.ColumnCount;
             string[,] a = new string[100, 100];
             string data;
             String DataQuery = "";

             for (int k = 0; k < (countRow - 1); k++)
             {
                 data = "'";
                 for (int j = 0; j < (countCol); j++)
                 {
                     a[j, k] = string.Format("" + dgvAList[j, k].Value);


                     if (j == 5)
                         data = data + a[j, k] + "'";
                     else
                         data = data + a[j, k] + "','";
                 }

                 DataQuery = "'" + TopicNumber + "'," + "'" + phase + "'," + data;
                 MessageBox.Show(DataQuery);
                 db.openConnection();

                 String query = @"Insert Action(TopicNo,Phase,Description,AssignedTo,DueDate,Status,DateCompleted,Comment) Values(" + DataQuery + ")";

                 SqlCommand command = new SqlCommand(query, DB.getConnection());

                 try
                 {
                     command.ExecuteNonQuery();
                 }
                 catch (Exception ex)
                 {
                     MessageBox.Show(ex.ToString());
                 }
                 db.closeConnection();


             }

Hoe can i validate DueDate and CompletedDate???

Please give me an answer for this ???
thanxx

Edited 6 Years Ago by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

@krishnisilva

Please read the rules before posting again, in particular the 'keep it organized' one - [icode]For easy readability, always wrap programming code within posts in (code blocks) and (inline code) tags. If you post a question and it gets resolved, please use the Mark Solved link to mark your thread solved. If you hit 10 infraction points your account gets an automatic ban, so it is worth obeying the rules if you want to continue to benefit from DaniWeb help.

Edited 3 Years Ago by mike_2000_17: Fixed formatting

this.dgvShortCut.CellValidating += new DataGridViewCellValidatingEventHandler(dgvShortCut_CellValidating);
private void dgvShortCut_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{   string ColName = dgvShortCut.Columns[e.ColumnIndex].Name;
    if (ColName.Equals("DOB"))
    {   if (string.IsNullOrEmpty(e.FormattedValue.ToString())) return;
        if (!Microsoft.VisualBasic.Information.IsDate(e.FormattedValue.ToString()))
        {   MessageBox.Show("Date Of Birth Date is not in correct format", "D.O.B", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            e.Cancel = true;
        }
    }
}

Edited 5 Years Ago by Ezzaral: Fixed tags and deleted 'fake sig' link. Please restrict personal links to your user signature, which can be edited through the control panel.

This article has been dead for over six months. Start a new discussion instead.