Datagridview数字格式

时间:2013-04-29 15:04:53

标签: vb.net datagridview numbers format

我正在尝试创建一个datagridview,它将自动格式化用户输入的数字。我的datagridview没有链接到数据源,它是以编程方式构建的:

Private Sub FormatGridView()
    Dim ILNumColumn As New DataGridViewTextBoxColumn
    Dim ArtNumColumn As New DataGridViewTextBoxColumn
    Dim DescColumn As New DataGridViewTextBoxColumn

    'Header text
    ILNumColumn.HeaderText = "# IL"
    ArtNumColumn.HeaderText = "# Articles"
    DescColumn.HeaderText = "Description"

    'Wrap
    DescColumn.DefaultCellStyle.WrapMode = DataGridViewTriState.True

    'Widths
    ILNumColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
    ArtNumColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
    DescColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill

    'Add columns
    dgvArticles.Columns.Add(ILNumColumn)
    dgvArticles.Columns.Add(ArtNumColumn)
    dgvArticles.Columns.Add(DescColumn)
End Sub

有没有办法让IlNumColumn始终采用绿色圆圈中的格式?

Number formatting

1 个答案:

答案 0 :(得分:0)

数字格式

'Formatting
ILNumColumn.DefaultCellStyle.Format = "000"

这将使IlNumColumn中的所有数字都为“001”格式。