2017-03-31 62 views
0

我有一个数据网格视图,并在列“2”(闹钟)我有时间添加如下图所示。vb.net在datagridview计算

enter image description here

而且在顶(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

的CellFormatting事件将是非常理想的。比迭代行效率更高你还应该打开'Option Strict',因为'icellResult = iCell1 +“10”'是无稽之谈。 '“10”'不是一个整数 – Plutonix

回答

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

+0

数据网格视图不是udpating :( – tharun

+0

您在哪个方法中放置了代码? –

+0

我已经在计时器中打勾了,这里是详细代码(见上) – tharun