日期:2014-05-16  浏览次数:20798 次

DataGridView时间值问题,请帮忙解决
 string strrowtime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");   

                foreach (DataGridViewRow dgvr in dataGridViewEx1.Rows)
                {
                  
                    dgvr.Cells["rowtime"].Value = strrowtime;
                    
                }

循环显示值:
                foreach (DataGridViewRow dgvr in dataGridViewEx1.Rows)
                {

                    MessageBox.Show(dgvr.Cells["rowtime"].Value.ToString());

                }

但是循环显示日期为 2014-03-03 21时31分29秒,我需要显示的时间为2014-03-03 21:31:29

如果把Value改为FormattedValue取值,那么显示就是正确的,但是我想使用Value取值,请问应该如何解决?
------解决方案--------------------
			dataGridViewCellStyle1.Format = "G";
this.Column1.DefaultCellStyle = dataGridViewCellStyle1;


这样Datagridview里显示的格式会变。
但是Messagebox还是有问题的,用1楼的可以改变messagebox的格式。