VB 中创建表格(1)
发布时间:2020-12-17 07:58:40 所属栏目:百科 来源:网络整理
导读:今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 Public Class Form1 Inherits System.Windows.Forms.FormPrivate Sub Form1_Load(ByVal sender As System.Object,ByVal e As System.EventArgs)_Handl
以下代码由PHP站长网 52php.cn收集自互联网 现在PHP站长网小编把它分享给大家,仅供参考 Public Class Form1 Inherits System.Windows.Forms.Form Private Sub Form1_Load(ByVal sender As System.Object,ByVal e As System.EventArgs)_ Handles MyBase.Load End Sub Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As_ System.EventArgs) Handles Button1.Click Dim Table1 As DataTable Table1 = New DataTable("Customers") 'creating a table named Customers Dim Row1,Row2,Row3 As DataRow 'declaring three rows for the table Try Dim Name As DataColumn = New DataColumn("Name") 'declaring a column named Name Name.DataType = System.Type.GetType("System.String") 'setting the datatype for the column Table1.Columns.Add(Name) 'adding the column to table Dim Product As DataColumn = New DataColumn("Product") Product.DataType = System.Type.GetType("System.String") Table1.Columns.Add(Product) Dim Location As DataColumn = New DataColumn("Location") Location.DataType = System.Type.GetType("System.String") Table1.Columns.Add(Location) Row1 = Table1.NewRow() 'declaring a new row Row1.Item("Name") = "Reddy" 'filling the row with values. Item property is used to set the field value. Row1.Item("Product") = "Notebook" 'filling the row with values. adding a product Row1.Item("Location") = "Sydney" 'filling the row with values. adding a location Table1.Rows.Add(Row1) 'adding the completed row to the table Row2 = Table1.NewRow() Row2.Item("Name") = "Bella" Row2.Item("Product") = "Desktop" Row2.Item("Location") = "Adelaide" Table1.Rows.Add(Row2) Row3 = Table1.NewRow() Row3.Item("Name") = "Adam" Row3.Item("Product") = "PDA" Row3.Item("Location") = "Brisbane" Table1.Rows.Add(Row3) Catch End Try Dim ds As New DataSet() ds = New DataSet() 'creating a dataset ds.Tables.Add(Table1) 'adding the table to dataset DataGrid1.SetDataBinding(ds,"Customers") 'binding the table to datagrid End Sub End Class 以上内容由PHP站长网【52php.cn】收集整理供大家参考研究 如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |