|
ผมก็นึกว่าดึงมาจากฐานข้อมูลก่อนครับ ... เพิ่ม Control เข้าไปดังนี้ ...
TextBox = txtProjectName
DateTimePicker = dtpDeadline
Button = btnAddRow
Button = btnRemoveRow
- Public Class frmCountDownGrid
- Private Sub frmCountDownGrid_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
- With DataGridView1
- '// Autosize Column
- .AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
- .AllowUserToAddRows = False
- .SelectionMode = DataGridViewSelectionMode.FullRowSelect
- End With
- With DataGridView1
- .ColumnCount = 3
- .Columns(0).Name = "Project Name"
- .Columns(1).Name = "Deadline"
- .Columns(2).Name = "Countdown"
- '.Rows.Add({"Project 1", "23/05/2564 00:00:00", ""})
- '.Rows.Add({"Project 2", "01/06/2565 00:00:00", ""})
- End With
- Timer1.Interval = 1000
- Timer1.Enabled = True
- '//
- txtProjectName.Clear()
- dtpDeadline.Format = DateTimePickerFormat.Custom
- dtpDeadline.CustomFormat = "dd MMMM yyyy hh:mm"
- dtpDeadline.Value = Now()
- End Sub
- Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
- For row As Integer = 0 To DataGridView1.Rows.Count - 1
- Dim StartDate As Date = DataGridView1.Rows(row).Cells(1).Value
- Dim EndDate As Date = Date.Now
- Dim TimeSpan As TimeSpan = StartDate.Subtract(EndDate)
- Dim DifDays As Integer = TimeSpan.Days
- Dim DifHr As Integer = TimeSpan.Hours
- Dim DifMin As Integer = TimeSpan.Minutes
- DataGridView1.Rows(row).Cells(2).Value = DifDays & " วัน, " & DifHr & " ชั่วโมง, " & DifMin & " นาที."
- Next
- End Sub
- Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles btnAddRow.Click
- If txtProjectName.Text.Trim.Length = 0 Then
- MessageBox.Show("กรุณาป้อนชื่อโปรเจค")
- txtProjectName.Focus()
- Exit Sub
- End If
- Call AddRow()
- End Sub
- Private Sub AddRow()
- Dim row As String()
- row = New String() {txtProjectName.Text, dtpDeadline.Value}
- DataGridView1.Rows.Add(row)
- '//
- txtProjectName.Clear()
- dtpDeadline.Value = Now()
- txtProjectName.Focus()
- End Sub
- Private Sub RemoveRow()
- '// Delete current row from DataGridView1
- If DataGridView1.RowCount = 0 Then Exit Sub
- DataGridView1.Rows.Remove(DataGridView1.CurrentRow)
- End Sub
- Private Sub btnRemove_Click(sender As System.Object, e As System.EventArgs) Handles btnRemoveRow.Click
- Call RemoveRow()
- End Sub
- End Class
คัดลอกไปที่คลิปบอร์ด
|
|