Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21292

Time format in DataGrid

$
0
0
I use the code below to populate a DataGrid. It does everything it should, it's just that I have a formatting problem.
grTimeMon, grTimeTue etc are DateTime and hold the time of a class. If, for example, a group has two classes a week of 1:30 on Tue at 16:00 and Fri at 19:30, then grTimeTue will hold 16:00 and grTimeFri will hold 19:30. All the others will hold zero (formatted as time).
I want to know if there is some way to display a space instead of "00:00" when the value is zero.

vb Code:
  1. Private Sub FillDGrid()
  2. Dim f As Integer
  3. Dim sSQL As String
  4.    sSQL = "SELECT grName AS [Group] , grHours AS [Length] ,grTimeMon AS Mon, grTimeTue AS Tue, grTimeWed AS Wed, "
  5.    sSQL = sSQL & " grTimeThu AS Thu, grTimeFri AS Fri, grTimeSat AS Sat, grTimeSun AS Sun "
  6.    sSQL = sSQL & " FROM tblGroup ORDER BY grName"
  7.    ShowData (sSQL)
  8.    dgGroup.Columns(0).Width = 1200
  9.    For f = 1 To 8
  10.       dgGroup.Columns(f).Width = 800
  11.       dgGroup.Columns(f).NumberFormat = "h:mm"
  12.    Next f
  13.    dgGroup.Columns(1).NumberFormat = "hh:mm"
  14. End Sub
  15.  
  16. Private Sub ShowData(ByVal sSQL As String)
  17.    Set conn = New ADODB.Connection
  18.    conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  19.                         "Data Source=" & App.Path & "\Student.mdb;Persist Security Info=False"
  20.    conn.Open
  21.    Set RecSet = New ADODB.Recordset
  22.    RecSet.CursorLocation = adUseClient
  23.    RecSet.Open sSQL, cn, adOpenKeyset, adLockPessimistic, adCmdText
  24.    Set dgGroup.DataSource = RecSet
  25.    dgGroup.Refresh
  26. End Sub

Viewing all articles
Browse latest Browse all 21292

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>