Windows Forms DataGridView Formatting

Time Formatting

To format Null set the Null Value in designer, or code for empty string.

Found when binding to a POCO class with TimeSpan that had some errors with some formats. hh\:mm seems to work.

To format 00:00 as blank then:

    Private Sub TimeDataGridView_CellFormatting(sender As System.Object, e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles TimeDataGridView.CellFormatting

        If e.ColumnIndex <> myColumn.Index Then
            Exit Sub
        End If
        If e.Value = New TimeSpan(0, 0, 0) Then
            e.Value = ""
            e.FormattingApplied = True
        End If

    End Sub


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: