DataGridView控件,放一個DataGridView1和Button1到窗體,下面是按鈕下代碼
創(chuàng)新互聯(lián)建站專注于網(wǎng)站建設(shè)|網(wǎng)站維護|優(yōu)化|托管以及網(wǎng)絡(luò)推廣,積累了大量的網(wǎng)站設(shè)計與制作經(jīng)驗,為許多企業(yè)提供了網(wǎng)站定制設(shè)計服務(wù),案例作品覆蓋成都石涼亭等行業(yè)。能根據(jù)企業(yè)所處的行業(yè)與銷售的產(chǎn)品,結(jié)合品牌形象的塑造,量身建設(shè)品質(zhì)網(wǎng)站。
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Me.DataGridView1.AllowUserToAddRows = False
DataGridView1.RowTemplate.Height = 200
DataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None
For i = 1 To 3
Me.DataGridView1.Columns.Add("列" i.ToString, "列" i.ToString)
Me.DataGridView1.Rows.Add()
Next
Me.DataGridView1.Columns(0).Width = 100
Me.DataGridView1.Columns(1).Width = 500
Me.DataGridView1.Columns(0).Width = 300
End Sub
'自己設(shè)置相關(guān)需要的屬性即可
DataGridView控件,放一個DataGridView1和Button1到窗體,下面是按鈕下代碼\x0d\x0a Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click\x0d\x0a Me.DataGridView1.AllowUserToAddRows = False\x0d\x0a DataGridView1.RowTemplate.Height = 200\x0d\x0a DataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None\x0d\x0a For i = 1 To 3\x0d\x0a Me.DataGridView1.Columns.Add("列" i.ToString, "列" i.ToString)\x0d\x0a Me.DataGridView1.Rows.Add()\x0d\x0a Next\x0d\x0a Me.DataGridView1.Columns(0).Width = 100\x0d\x0a Me.DataGridView1.Columns(1).Width = 500\x0d\x0a Me.DataGridView1.Columns(0).Width = 300\x0d\x0a End Sub\x0d\x0a'自己設(shè)置相關(guān)需要的屬性即可
Dim n As Integer
For i = 0 To 14 '如果要全部列的寬度,14改成DataGridView1.ColumnCount-1
n += DataGridView1.Columns(i).Width
Next
Debug.WriteLine(n.ToString)
With Me.ReportViewer1 '初始化報表
.Dock = DockStyle.Fill
.LocalReport.DataSources.Clear()
.LocalReport.ReportPath = "Report1.rdlc"
.RefreshReport()
End With
報表在設(shè)計時,不一定要綁定數(shù)據(jù)源,但在窗體加載時,需要初始化報表控件,以上代碼可以放在窗體加載的Load事件里,供你參考。
VB中表格控件有很多,如MSFlexGrid,DataGrid,MSHFlexGrid等等
使用的多的是微軟的FlexGrid控件。
通過菜單"Project" - "Components" - 勾上"Microsoft FlexGrid Control 6.0"進行選擇。這個是包含在VS6 SP6安裝包內(nèi)的。