我正在尝试创建一个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
始终采用绿色圆圈中的格式?
答案 0 :(得分:0)
'Formatting
ILNumColumn.DefaultCellStyle.Format = "000"
这将使IlNumColumn中的所有数字都为“001”格式。