我有一個數據網格視圖,並在列「2」(鬧鐘)我有時間添加如下圖所示。vb.net在datagridview計算
而且在頂(label9)的標籤。如果標籤文本顯示爲「星期五」,則「警報時間」單元格值應該添加10分鐘。 示例如果標籤顯示星期五,則時間應從16:10:00
更改爲16:20:00
。
我的代碼:
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Dim myform As New Form2
DataGridView1.Columns(2).DefaultCellStyle.Format = "h:mm:ss"
For i As Integer = 0 To DataGridView1.Rows.Count - 1
If Me.DataGridView1.Rows(i).Cells("AlarmTime").Value = Me.MetroLabel2.Text And Me.DataGridView1.Rows(i).Cells("Frequency").Value = "Weekday" Then
myform.Show()
myform.msgdisply.Text = Me.DataGridView1.Rows(i).Cells("UpdateName").Value
If Me.MetroLabel9.Text = "FRIDAY" Then
Dim iCell1 As String
Dim dt As DateTime
iCell1 = Me.DataGridView1.Rows(i).Cells("AlarmTime").Value
dt = Format(DateTime.Parse(iCell1), "h:mm:ss")
dt.AddMinutes(10)
Me.DataGridView1.Rows(i).Cells("AlarmTime").Value = dt.ToString
End If
next
的CellFormatting事件將是非常理想的。比迭代行效率更高你還應該打開'Option Strict',因爲'icellResult = iCell1 +「10」'是無稽之談。 '「10」'不是一個整數 – Plutonix