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.

http://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx

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

End
Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: