我创建了一个程序,我使用数据表来存储一些信息,然后单击按钮,它将显示在 datagridview 中。这是我的代码......有人可以告诉我如何创建一个数组而不是这个,我研究了几个小时仍然没有帮助。
Dim Array As New DataTable
Dim array2 As New DataTable
Dim array3 As New DataTable
Public Class Degrees
Public Property FieldofStudy As String
Public Property Year1986 As String
Public Property Year2006 As String
Public Sub New(ByVal FieldofStudy As String, ByVal Year1986 As String, ByVal Year2006 As String)
Me.FieldofStudy = FieldofStudy
Me.Year1986 = Year1986
Me.Year1986 = Year2006
End Sub
End Class
Private Sub btnChanges_Click(sender As System.Object, e As System.EventArgs) Handles btnChanges.Click
array2.Clear()
Dim column4 As DataColumn = New DataColumn("Field of Study")
column4.DataType = System.Type.GetType("System.String")
Dim column5 As DataColumn = New DataColumn("Change (1981-2006)")
column5.DataType = System.Type.GetType("System.String")
array2.Columns.Add(column4)
array2.Columns.Add(column5)
''Display array two containing percentage changes''
array2.Rows.Add("Computer and info. science", "214.0%")
array2.Rows.Add("Social sciences and history", "60.7%")
array2.Rows.Add("Business", "58.6%")
array2.Rows.Add("Engineering", "5.3%")
array2.Rows.Add("Education", "-0.8%")
dgvStudies.DataSource = array2
End Sub
Private Sub btnHistogram_Click(sender As System.Object, e As System.EventArgs) Handles btnHistogram.Click
array3.Clear()
Dim column6 As DataColumn = New DataColumn("Field of Study")
column6.DataType = System.Type.GetType("System.String")
Dim column7 As DataColumn = New DataColumn("")
column7.DataType = System.Type.GetType("System.String")
Dim column8 As DataColumn = New DataColumn("Degrees in 2006")
column8.DataType = System.Type.GetType("System.String")
array3.Clear()
array3.Columns.Add(column6)
array3.Columns.Add(column7)
array3.Columns.Add(column8)
array3.Rows.Add("Computer and info. science", "*****", "47,480")
array3.Rows.Add("Engineering", "*******", "67,045")
array3.Rows.Add("Education", "***********", "107,238")
array3.Rows.Add("Social sciences and history", "****************", "161,485")
array3.Rows.Add("Business", "********************************", "67,045")
dgvStudies.DataSource = array3
End Sub
Private Sub btnQuit_Click_1(sender As System.Object, e As System.EventArgs) Handles btnQuit.Click
Me.Close()
End Sub
Private Sub btnDegrees_Click_1(sender As System.Object, e As System.EventArgs) Handles btnDegrees.Click
Array.Clear()
Dim column1 As DataColumn = New DataColumn("Field of Study")
column1.DataType = System.Type.GetType("System.String")
Dim column2 As DataColumn = New DataColumn("1981")
column2.DataType = System.Type.GetType("System.String")
Dim column3 As DataColumn = New DataColumn("2006")
column3.DataType = System.Type.GetType("System.String")
Array.Clear()
Array.Columns.Add(column1)
Array.Columns.Add(column2)
Array.Columns.Add(column3)
Array.Rows.Add("Business", "200,521", "318,042")
Array.Rows.Add("Computer and info. science", "15,121", "47,480")
Array.Rows.Add("Education", "108,074", "107,238")
Array.Rows.Add("Engineering", "63,642", "67,045")
Array.Rows.Add("Social sciences and history", "100,513", "161,485")
Me.dgvStudies.DataSource = Array
End Sub
结束类