【发布时间】:2011-11-09 08:40:01
【问题描述】:
我有一个带有列的数据网格,ID 的值类似于 1,2,3,4,5....10,11,12,13... 我希望所有值的长度为 2,这意味着我希望值为 01,02,03....10,11,12... 怎么做?
编辑 我正在使用 Winforms。
编辑
if (dg.Columns[e.ColumnIndex].Name == "Id")
{
try
{
//e.Value = String.Format("{0:00.0}", e.Value);
DataGridViewCellStyle ca = new DataGridViewCellStyle();
ca.ForeColor = System.Drawing.Color.Red;
ca.Format = "d2";
dg.Columns[e.ColumnIndex].DefaultCellStyle = ca;
e.FormattingApplied = true;
}
catch (FormatException)
{
e.FormattingApplied = false;
}
}
我可以在这里更改背景颜色和前景色,但无论我做什么,文本格式都保持不变。我什至尝试使用 String.Format (注释行),但它也不起作用。 我也试过你的代码,它不起作用。不知道怎么回事。
【问题讨论】:
标签: .net winforms c#-4.0 datagrid