Private Sub FrmYukashokenDaichoPrint_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'OleDbDataAdapter1.Fill(DsSokanjomotochonoshokai1, "TbKurikosi712") 'データセットにテーブルを追加する
lblNendo.Text = "平成16年度"
Dim dtSet As DataSet = New DataSet("tbkurikosi") Dim dtTable As DataTable Dim pkCol As DataColumn
'行の幅を設定する Dim tblstyle As DataGridTableStyle Dim clmstyle1 As DataGridColumnStyle = New DataGridTextBoxColumn Dim clmstyle2 As DataGridColumnStyle = New DataGridTextBoxColumn Dim clmstyle3 As DataGridColumnStyle = New DataGridTextBoxColumn Dim clmstyle4 As DataGridColumnStyle = New DataGridTextBoxColumn Dim clmstyle5 As DataGridColumnStyle = New DataGridTextBoxColumn Dim clmstyle6 As DataGridColumnStyle = New DataGridTextBoxColumn Dim clmstyle7 As DataGridColumnStyle = New DataGridTextBoxColumn Dim clmstyle8 As DataGridColumnStyle = New DataGridTextBoxColumn 'Dim clmstyle7 As DataGridColumnStyle = New DataGridTextBoxColumn
分類:[.NET]
はじめまして、まちと申します。
DataGridのヘッダーを複数行表示させたいのですが、
方法がわかりません。
言語はVB.NETです。
現在はヘッダーを使用せず、ラベルで項目を表示させているのですが、
それではあまり見た目が良くないので、何とかヘッダーを2行にさせたいのです。
よろしくお願いします。
以下、現在のコードです。
Private Sub FrmYukashokenDaichoPrint_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'OleDbDataAdapter1.Fill(DsSokanjomotochonoshokai1, "TbKurikosi712")
'データセットにテーブルを追加する
lblNendo.Text = "平成16年度"
Dim dtSet As DataSet = New DataSet("tbkurikosi")
Dim dtTable As DataTable
Dim pkCol As DataColumn
'データセットにテーブルを追加する
dtTable = dtSet.Tables.Add("t_有価証券")
'テーブルにフィールドを追加する
'pkCol = dtTable.Columns.Add( _
' "ID", Type.GetType("System.String"))
dtTable.Columns.Add( _
"日付", Type.GetType("System.String"))
dtTable.Columns.Add( _
"摘要", Type.GetType("System.String"))
dtTable.Columns.Add( _
"増減数量", Type.GetType("System.String"))
dtTable.Columns.Add( _
"増減価格", Type.GetType("System.String"))
dtTable.Columns.Add( _
"現在数量", Type.GetType("System.String"))
dtTable.Columns.Add( _
"現在価格", Type.GetType("System.String"))
dtTable.Columns.Add( _
"受取利息日付", Type.GetType("System.String"))
dtTable.Columns.Add( _
"受取利息金額", Type.GetType("System.String"))
'dtTable.PrimaryKey = New DataColumn() {pkCol}
'テーブルにレコードを追加する。
dtTable.Rows.Add(New Object() {"16年" & Chr(10) & "04.05", "新規設定", "1", "5,000,000", "1", "5,000,000", "16年" & Chr(10) & "04.05", "5,000,000"})
dtTable.Rows.Add(New Object() {"16年" & Chr(10) & "04.05", "新規設定", "1", "5,000,000", "1", "5,000,000", "16年" & Chr(10) & "04.05", "5,000,000"})
dtTable.Rows.Add(New Object() {"16年" & Chr(10) & "04.05", "新規設定", "1", "5,000,000", "1", "5,000,000", "16年" & Chr(10) & "04.05", "5,000,000"})
dtTable.Rows.Add(New Object() {"16年" & Chr(10) & "04.05", "新規設定", "1", "5,000,000", "1", "5,000,000", "16年" & Chr(10) & "04.05", "5,000,000"})
'行の幅を設定する
Dim tblstyle As DataGridTableStyle
Dim clmstyle1 As DataGridColumnStyle = New DataGridTextBoxColumn
Dim clmstyle2 As DataGridColumnStyle = New DataGridTextBoxColumn
Dim clmstyle3 As DataGridColumnStyle = New DataGridTextBoxColumn
Dim clmstyle4 As DataGridColumnStyle = New DataGridTextBoxColumn
Dim clmstyle5 As DataGridColumnStyle = New DataGridTextBoxColumn
Dim clmstyle6 As DataGridColumnStyle = New DataGridTextBoxColumn
Dim clmstyle7 As DataGridColumnStyle = New DataGridTextBoxColumn
Dim clmstyle8 As DataGridColumnStyle = New DataGridTextBoxColumn
'Dim clmstyle7 As DataGridColumnStyle = New DataGridTextBoxColumn
tblstyle = New DataGridTableStyle
tblstyle.MappingName = "t_有価証券"
grdYukashoken.TableStyles.Add(tblstyle)
grdYukashoken.ReadOnly = True
grdYukashoken.ColumnHeadersVisible = False
clmstyle1.MappingName = "日付"
clmstyle1.Width = 80
clmstyle1.HeaderText = "日付"
clmstyle1.Alignment = HorizontalAlignment.Left
clmstyle1.ReadOnly = True
tblstyle.GridColumnStyles.Add(clmstyle1)
clmstyle2.MappingName = "摘要"
clmstyle2.Width = 240
clmstyle2.HeaderText = "摘要"
clmstyle2.Alignment = HorizontalAlignment.Left
clmstyle2.ReadOnly = True
tblstyle.GridColumnStyles.Add(clmstyle2)
clmstyle3.MappingName = "増減数量"
clmstyle3.Width = 60
clmstyle3.HeaderText = "数量"
clmstyle3.Alignment = HorizontalAlignment.Right
clmstyle3.ReadOnly = True
tblstyle.GridColumnStyles.Add(clmstyle3)
clmstyle4.MappingName = "増減価格"
clmstyle4.Width = 100
clmstyle4.HeaderText = "価格"
clmstyle4.Alignment = HorizontalAlignment.Right
clmstyle4.ReadOnly = True
tblstyle.GridColumnStyles.Add(clmstyle4)
clmstyle5.MappingName = "現在数量"
clmstyle5.Width = 60
clmstyle5.HeaderText = "数量" & " "
clmstyle5.Alignment = HorizontalAlignment.Right
clmstyle5.ReadOnly = True
tblstyle.GridColumnStyles.Add(clmstyle5)
clmstyle6.MappingName = "現在価格"
clmstyle6.Width = 100
clmstyle6.HeaderText = "価格"
clmstyle6.Alignment = HorizontalAlignment.Right
clmstyle6.ReadOnly = True
tblstyle.GridColumnStyles.Add(clmstyle6)
clmstyle7.MappingName = "受取利息日付"
clmstyle7.Width = 100
clmstyle7.HeaderText = "日付"
clmstyle7.Alignment = HorizontalAlignment.Left
clmstyle7.ReadOnly = True
tblstyle.GridColumnStyles.Add(clmstyle7)
clmstyle8.MappingName = "受取利息金額"
clmstyle8.Width = 100
clmstyle8.HeaderText = "金額"
clmstyle8.Alignment = HorizontalAlignment.Right
clmstyle8.ReadOnly = True
tblstyle.GridColumnStyles.Add(clmstyle8)
'clmstyle7.MappingName = "残高"
'clmstyle7.Width = 160
'clmstyle7.HeaderText = "残高"
'clmstyle7.Alignment = HorizontalAlignment.Right
'clmstyle7.ReadOnly = True
'tblstyle.GridColumnStyles.Add(clmstyle7)
'行の高さを設定する
tblstyle.PreferredRowHeight = 40
tblstyle.RowHeadersVisible = False
tblstyle.HeaderBackColor = Color.PaleGreen
'データグリッドにテーブルを表示する
grdYukashoken.SetDataBinding(dtSet, "t_有価証券")
End Sub
(データは架空のものです。)