2017-03-31 107 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