Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
datagridview中的vb.net计算_Vb.net_Datagridview - Fatal编程技术网

datagridview中的vb.net计算

datagridview中的vb.net计算,vb.net,datagridview,Vb.net,Datagridview,我有一个数据网格视图,在列“2”(alarmtime)中添加了时间,如下图所示 顶部有一个标签(标签9)。如果标签文本显示为“星期五”,则“报警时间”单元格值应增加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

我有一个数据网格视图,在列“2”(alarmtime)中添加了时间,如下图所示

顶部有一个标签(标签9)。如果标签文本显示为“星期五”,则“报警时间”单元格值应增加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
试试这个:

Dim dt as datetime
dt = datetime.parse(iCell1)
dt.addminutes(10)
Me.DataGridView1.Rows(i).Cells("AlarmTime").Value = dt.ToString("HH:mm")

您可以查看
addminutes
方法信息

CellFormatting事件非常适合此操作。与迭代行相比,您还应该启用
选项Strict
,因为
icellResult=iCell1+“10”
毫无意义<代码>“10”不是整数数据网格视图没有udpating:(我已在计时器刻度中放置,这是详细代码。(参见上文)您确定
计时器
正在启动吗?使用
调试.Print
计算
Me.DataGridView1.Rows(i).Cells(“AlarmTime”).Value
并确保值与预期值一致。感谢Dave,我在将单元格格式设置为“h:mm:ss”时遇到了问题。它也带有日期(例如:1990.10.01,6:10:00)。如何将单元格格式设置为仅限时间我已更新了代码。您应该指定将单元格与之进行比较的时间的字符串格式。