我有一个数据网格视图,在列“2”(闹钟时间)中,我添加了一些时间,如下图所示。
顶部有一个标签(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
答案 0 :(得分:0)
试试这个:
Dim dt as datetime
dt = datetime.parse(iCell1)
dt.addminutes(10)
Me.DataGridView1.Rows(i).Cells("AlarmTime").Value = dt.ToString("HH:mm")
您可以查看addminutes
方法信息Here