在DataGridView中指定日期列的格式

chaoyang0502發表於2008-08-06

private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            if (e.ColumnIndex == 3)//假設第3列為顯示日期的列
            {
                e.Value = Convert.ToDateTime(e.Value).ToString("yyyy/MM/dd ",System.Globalization.DateTimeFormatInfo.InvariantInfo);
                //dataGridView1.Columns[3].DefaultCellStyle.Format = "d";
            }           
        }

相關文章