0

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

3
Contributors
4
Replies
10
Views
7 Years
Discussion Span
Last Post by FijiXzone.com
0

>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;
0

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 by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

0

@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 by mike_2000_17: Fixed formatting

0
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 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 topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.