Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DataGridView1.Rows.Clear()
DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
DataGridView1.MultiSelect = False
End Sub
Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
DataGridView1.Rows.Add("資料 " & DataGridView1.Rows.Count & " - 1", "資料 " & DataGridView1.Rows.Count & " - 2", "資料 " & DataGridView1.Rows.Count & " - 3")
ToolStripButton6.Enabled = False
ToolStripButton2.Enabled = False
ToolStripButton3.Enabled = False
ToolStripButton4.Enabled = False
ToolStripButton5.Enabled = False
End Sub
Private Sub ToolStripButton6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton6.Click
DataGridView1.Rows.RemoveAt(DataGridView1.CurrentRow.Index)
End Sub
Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click
DataGridView1.Rows.Insert(0, DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells(0).Value, DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells(1).Value, DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells(2).Value)
DataGridView1.Rows.RemoveAt(DataGridView1.CurrentRow.Index)
DataGridView1.Rows(0).Cells(0).Selected = True
End Sub
Private Sub ToolStripButton3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton3.Click
Dim i As Single = DataGridView1.CurrentRow.Index
If i = 0 Then
ToolStripButton5_Click(sender, e)
Else
DataGridView1.Rows.Insert(i - 1, DataGridView1.Rows(i).Cells(0).Value, DataGridView1.Rows(i).Cells(1).Value, DataGridView1.Rows(i).Cells(2).Value)
DataGridView1.Rows.RemoveAt(DataGridView1.CurrentRow.Index)
DataGridView1.Rows(i - 1).Cells(0).Selected = True
End If
End Sub
Private Sub ToolStripButton4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton4.Click
Dim i As Single = DataGridView1.CurrentRow.Index
If i >= DataGridView1.Rows.Count - 2 Then
ToolStripButton2_Click(sender, e)
Else
DataGridView1.Rows.Insert(i + 2, DataGridView1.Rows(i).Cells(0).Value, DataGridView1.Rows(i).Cells(1).Value, DataGridView1.Rows(i).Cells(2).Value)
DataGridView1.Rows.RemoveAt(DataGridView1.CurrentRow.Index)
DataGridView1.Rows(i + 1).Cells(0).Selected = True
End If
End Sub
Private Sub ToolStripButton5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton5.Click
DataGridView1.Rows.Insert(DataGridView1.Rows.Count - 1, DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells(0).Value, DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells(1).Value, DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells(2).Value)
DataGridView1.Rows.RemoveAt(DataGridView1.CurrentRow.Index)
DataGridView1.Rows(DataGridView1.Rows.Count - 2).Cells(0).Selected = True
End Sub
Private Sub DataGridView1_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGridView1.SelectionChanged
ToolStripStatusLabel1.Text = DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells(0).Value
ToolStripStatusLabel2.Text = DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells(1).Value
ToolStripStatusLabel3.Text = DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells(2).Value
End Sub
Private Sub DataGridView1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGridView1.Click
If DataGridView1.CurrentRow.Index < DataGridView1.Rows.Count - 1 Then
ToolStripButton6.Enabled = True
ToolStripButton2.Enabled = True
ToolStripButton3.Enabled = True
ToolStripButton4.Enabled = True
ToolStripButton5.Enabled = True
Else
ToolStripButton6.Enabled = False
ToolStripButton2.Enabled = False
ToolStripButton3.Enabled = False
ToolStripButton4.Enabled = False
ToolStripButton5.Enabled = False
End If
End Sub
End Class