Datagridview Number Format

2019-08-30 18:16发布

I am trying to create a datagridview that will automatically format the numbers that a user enters. My datagridview is not linked to a datasource, it is built programmatically like so:

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

Is there a way to make the IlNumColumn always be in the format below in the green circle?

Number formatting

1条回答
Viruses.
2楼-- · 2019-08-30 18:58

Number format

'Formatting
ILNumColumn.DefaultCellStyle.Format = "000"

This will make all the numbers in the IlNumColumn in a "001" format.

查看更多
登录 后发表回答