datagridview怎么制作表格 方法教程
来源: 吾爱经验软件园 编辑:BT手游 更新:2018-07-18 17:33:18
datagridview怎么制作表格??程序构通时,产生一个table,如何在datagridview上显示表格呢?其实很简单,我来给大家演示生成表格的几种方法!
第一种:
大家可以直接通过代码生成一个可视化的表格
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim dgv As New DataGridView
Dim dt As New DataTable
dt.Columns.Add("Id")
dt.Columns.Add("Name")
Dim r = dt.NewRow()
r(0) = "1"
r(1) = "AAA"
dt.Rows.Add(r)
r = dt.NewRow()
r(0) = "2"
r(1) = "AAACC"
dt.Rows.Add(r)
r = dt.NewRow()
r(0) = "4"
r(1) = "A"
dt.Rows.Add(r)
With dgv
.Name = "dgv"
.Dock = DockStyle.Fill
.DataSource = dt
End With
Me.Controls.Add(dgv)
End Sub
End Class
第二种方法:
使用C#来完成实例
this.dataGridViewG1.AllowUserToAddRows = false;
this.dataGridViewG1.AllowUserToDeleteRows = false;
this.dataGridViewG1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridViewG1.GridColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(128)))), ((int)(((byte)(255)))));
this.dataGridViewG1.Location = new System.Drawing.Point(12, 12);
this.dataGridViewG1.Name = "dataGridViewG1";
this.dataGridViewG1.ReadOnly = true;
this.dataGridViewG1.RowTemplate.Height = 27;
this.dataGridViewG1.Size = new System.Drawing.Size(250, 250);
this.dataGridViewG1.TabIndex = 0;
this.dataGridViewG1.RowCount = 5;
this.dataGridViewG1.ColumnCount = 5;
欢迎玩家到【 】查看最新变态版手游攻略,只需要在百度输入【 】就可以浏览最新上线送满vip的变态手游攻略了,更多有关手游的攻略和资讯,敬请关注玩的好手游网!