我有一个数据网格视图,并在列“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