Search code examples
c#sqldatagridwindows-mobilecompact-framework

Modify how datetime is presented in a datagrid?


I'm querying an SQL CE database to bind up a datasource for a datagrid to display some information.

One of the columns in the SQL CE database is a DateTime column. In the datagrid it displays the full date and time, what I'd like it to do is display the date in this format: mm/dd/yyyy

How can I go about doing this?


Solution

  • If you know which column has date you could modify property of cell style for column:

    System.Windows.Forms.DataGridViewCellStyle dgvCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
    dgvCellStyle1.Format = "MM/dd/yyyy";
    dgvCellStyle1.NullValue = null;
    this.dataGridView1.Columns[0].DefaultCellStyle = dgvCellStyle1;