我嘗試用 Form1.Controls.Add "MsDatagridLib.Datagrid", "NewDatagrid", DataGrid1
但是不行。
請問怎樣【用代碼實作】在表單中添加Datagrid,而不是用工具箱畫?
uj5u.com熱心網友回復:
Private Sub Command1_Click()Dim tGrid As MSDataGridLib.DataGrid
Me.Controls.Add "MsDatagridLib.Datagrid", "Grid1", Me
Set tGrid = Controls("Grid1")
tGrid.Visible = True
End Sub
uj5u.com熱心網友回復:
如果我是從另一個表單,比如Form2
給Form1 里面 加一個Datagrid
都有哪些地方應該改動?
我改了您其中的 Me
但報錯說: 找不到Grid1
還需要哪些改動?
謝謝!
uj5u.com熱心網友回復:
首先,選單 Project\Components... 對話框把 Microsoft DataGrid Control 6.0 選上。其次,工程屬性 Make 頁的 Remove information abount unused ActiveX Controls 打勾要去掉,避免設計表單沒使用的控制元件不初始化。
最后,才能動態創建
'Form2
Option Explicit
Private Sub Command1_Click()
Dim dgrd As MSDataGridLib.DataGrid
Set dgrd = Form1.Controls.Add("MsDatagridLib.Datagrid", "DataGrid1", Form1)
dgrd.Visible = True
End Sub
uj5u.com熱心網友回復:
不會改,那就把我那個代碼做成Form1的一個函式A(),另一個表單直接呼叫函式Form1.A()就行,別的什么都不用改uj5u.com熱心網友回復:
拖一個DataGrid控制元件到表單中,設定Visible為False,Index為0,Name為DataGrids想添加時Load DataGrids(1):DataGrids(1).Visible=True
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/99689.html
標籤:控件
