DataGridView列格式 [英] DataGridView column format

查看:104
本文介绍了DataGridView列格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读到DGV

public void ReadFromDB()
{
    dataset = DB.ReadFromDB("SELECT * FROM orders");
    dataGridView1.DataSource = dataset.Tables[0];

    //another columns....

    DataGridViewColumn sellDate = new DataGridViewTextBoxColumn();
    sellDate.DataPropertyName = "sell_date";
    sellDate.ReadOnly = true;
    sellDate.Name = "Дата продажи";
    dataGridView1.Columns.Add(sellDate);
    dataGridView1.Columns[4].DefaultCellStyle.Format = "dd/MM/yyyy";
    dataGridView1.Columns[4].Width = 80;
    dataGridView1.Update();
}

为什么格式化不起作用?
DefaultCellStyle.Format设置为:

Why formatting doesn't work? DefaultCellStyle.Format is set:

屏幕http://img29.imageshack.us/img29/8056/8trw.jpg

推荐答案

p>它可能是斜杠/反斜杠问题。尝试这样:

it may be the slash/backslash issue. Try this:

dataGridView1.Columns[4].DefaultCellStyle.Format = "dd\\/MM\\/yyyy";

dataGridView1.Columns[4].DefaultCellStyle.Format = @"dd\/MM\/yyyy";

这篇关于DataGridView列格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆