我看过论坛,似乎无法找到任何可以帮助我的东西。我以十进制格式从SQL中抽出时间,不要问我为什么,我知道这样做没有多大意义,特别是当有时间变量,甚至是字符时。无论如何,格式是HH.MM.当我从SQL中提取数据时,我将它放入一个字符串中,稍加格式化,然后将其添加到datagridview中的一列中。问题是,当添加到datagridview时,它不会显示。价值在那里,我可以通过消息框或控制台输出,但它不会显示。有小费吗?我认为这可能与我为细胞分配值的方式有关,但我可能错了,显然我无法弄明白。
Public Sub RefreshRoutes()
Dim cmd As New SqlCommand
Dim ds As New DataSet
Dim row As DataGridViewRow
Dim iHour, iMinutes As Byte
Dim dTime As Decimal
Dim sTime As String
Dim i As Short
dgvRoutes.Columns.Clear()
If Form1.SQLCon.State <> ConnectionState.Open Then
Form1.OpenDatabase()
End If
cmd = New SqlCommand("Pull_Detailed_Routes", Form1.SQLCon)
cmd.CommandType = CommandType.StoredProcedure
Dim Adapter As New SqlDataAdapter(cmd)
Adapter.SelectCommand.CommandTimeout = 300
Adapter.Fill(ds, "DataSet")
Adapter.Dispose()
cmd.Dispose()
dgvRoutes.DataSource = Nothing
dgvRoutes.DataSource = ds.Tables(0)
dgvRoutes.Columns("ID").Visible = False
dgvRoutes.Columns.Add("Time", "Start Time")
'dgvRoutes.Columns("StarTime").Visible = False
ds.Dispose()
For i = 0 To dgvRoutes.ColumnCount - 1
dgvRoutes.Columns(i).DefaultCellStyle.BackColor = Color.Gainsboro
Next
'dgvRoutes.Columns.Insert(2, TimeColumn)
For i = 0 To dgvRoutes.RowCount - 1
row = dgvRoutes.Rows(i)
sTime = ""
dTime = row.Cells("StarTime").Value
iMinutes = (dTime Mod 1) * 100
iHour = dTime - dTime Mod 1
If iHour < 10 Then
sTime = "0"
End If
sTime = sTime & iHour & ":"
If iMinutes < 10 Then
sTime = sTime & "0"
End If
sTime = sTime & iMinutes
dgvRoutes.Rows(i).Cells("Time").Value = sTime
'MsgBox(row.Cells("Time").Value.ToString)
Next
dgvRoutes.Columns("Time").DisplayIndex = 10
End Sub
由于