我想在 DataGridView 中显示一个带有前导零的数字,但我不知道如何操作。
例如:
3910323 → 03910323
我尝试向 DataGridView 中的 int/string 添加前导零,并且由于某种原因 DataGridView 发出零。
如何以显示前导零的方式设置单元格格式?
这是我的代码:
string number = dgvCustomers[0, 0].Value.ToString();
number = "0" + number;
dgvCustomers[0, 0].Value = number;
尝试使用
dgv.Columns["myColumn"].DefaultCellStyle.Format = "D9";
在添加数据之前。
更多信息在这里: C# 中 Datagridview 的数字格式
也许这会有所帮助
string number = (string)DataGridView1[iCol, iRow].Value;
number = number.PadLeft(8, '0');
DataGridView1[iCol, iRow].Value = number;
基本。使用数据网格自定义格式。月/日/年 像精灵一样工作。