我正在使用vb.net上的gridview进行webforms,我必须在此表中为特定的列组添加标题..但我不知道如何做到这一点,这是我的一个例子想:
“学生信息”,“主题信息”和“部分成绩”是我需要添加的标题。
答案 0 :(得分:1)
默认的Datagridview没有你想要的选项。 您可以尝试devexpress(它在gridcontrol中有属性的音调) 你可以创建自己的控件,就像你的“TITLE LABELS”
一样Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim DataGridView1 = New System.Windows.Forms.DataGridView()
Dim Column1 = New System.Windows.Forms.DataGridViewTextBoxColumn()
Dim Column2 = New System.Windows.Forms.DataGridViewTextBoxColumn()
Dim Column3 = New System.Windows.Forms.DataGridViewTextBoxColumn()
Dim TableLayoutPanel1 = New System.Windows.Forms.TableLayoutPanel()
Dim Label1 = New System.Windows.Forms.Label()
Dim Label2 = New System.Windows.Forms.Label()
'DataGridView1
DataGridView1.BorderStyle = System.Windows.Forms.BorderStyle.None
DataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize
DataGridView1.Columns.AddRange(New System.Windows.Forms.DataGridViewColumn() {Column1, Column2, Column3})
DataGridView1.Location = New System.Drawing.Point(13, 78)
DataGridView1.Name = "DataGridView1"
DataGridView1.RowHeadersVisible = False
DataGridView1.Size = New System.Drawing.Size(397, 228)
DataGridView1.TabIndex = 0
DataGridView1.Name = "dgv"
AddHandler DataGridView1.ColumnWidthChanged, AddressOf DataGridView1_ColumnWidthChanged
'
'Column1
'
Column1.HeaderText = "Column1"
Column1.Name = "Column1"
'
'Column2
'
Column2.HeaderText = "Column2"
Column2.Name = "Column2"
'
'Column3
'
Column3.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill
Column3.HeaderText = "Column3"
Column3.Name = "Column3"
'
'TableLayoutPanel1
'
TableLayoutPanel1.ColumnCount = 2
TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 53.98936!))
TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 195.0!))
TableLayoutPanel1.Controls.Add(Label2, 1, 0)
TableLayoutPanel1.Controls.Add(Label1, 0, 0)
TableLayoutPanel1.Location = New System.Drawing.Point(12, 51)
TableLayoutPanel1.Name = "TableLayoutPanel1"
TableLayoutPanel1.RowCount = 1
TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50.0!))
TableLayoutPanel1.Size = New System.Drawing.Size(398, 29)
TableLayoutPanel1.TabIndex = 1
TableLayoutPanel1.CellBorderStyle = System.Windows.Forms.TableLayoutPanelCellBorderStyle.[Single]
TableLayoutPanel1.Name = "title"
'
'Label1
'
Label1.Anchor = System.Windows.Forms.AnchorStyles.None
Label1.AutoSize = True
Label1.Location = New System.Drawing.Point(82, 8)
Label1.Name = "Label1"
Label1.Size = New System.Drawing.Size(39, 13)
Label1.TabIndex = 0
Label1.Text = "Label1"
'
'Label2
'
Label2.Anchor = System.Windows.Forms.AnchorStyles.None
Label2.AutoSize = True
Label2.Location = New System.Drawing.Point(281, 8)
Label2.Name = "Label2"
Label2.Size = New System.Drawing.Size(39, 13)
Label2.TabIndex = 1
Label2.Text = "Label2"
'
'Form1
'
Me.Controls.Add(TableLayoutPanel1)
Me.Controls.Add(DataGridView1)
End Sub
Private Sub DataGridView1_ColumnWidthChanged(sender As Object, e As DataGridViewColumnEventArgs)
Dim title As TableLayoutPanel = CType(Me.Controls("title"), TableLayoutPanel)
Dim dgv As DataGridView = CType(Me.Controls("dgv"), DataGridView)
title.ColumnStyles(0).Width = dgv.Columns(0).Width + dgv.Columns(1).Width
title.ColumnStyles(1).Width = dgv.Columns(2).Width
End Sub
结束班