Home > Software engineering >  [how to dynamically add Datagrid?]
[how to dynamically add Datagrid?]

Time:09-30

I try to use Form1. Controls. Add "MsDatagridLib. Datagrid", "NewDatagrid," DataGrid1
But no,
How [code] in the form, please add the Datagrid, rather than using the toolkit?

CodePudding user response:

Private Sub Command1_Click ()
Dim tGrid As MSDataGridLib. DataGrid
Me. Controls. Add "MsDatagridLib Datagrid", "Grid1", the Me
The Set tGrid=Controls (" Grid1 ")
TGrid. Visible=True

End Sub

CodePudding user response:

reference 1/f, worldy response:
Private Sub Command1_Click ()
Dim tGrid As MSDataGridLib. DataGrid
Me. Controls. Add "MsDatagridLib Datagrid", "Grid1", the Me
The Set tGrid=Controls (" Grid1 ")
TGrid. Visible=True

End Sub

If I am from another form, such as Form2
Add a Datagrid to Form1
What are the places should change?
I changed you including Me
But an error says: can't find Grid1
Also need to change?
Thank you very much!

CodePudding user response:

First of all, the menu Project \ Components... Dialog box to Microsoft DataGrid Control 6.0 are chosen,
Secondly, project properties page Make Remove information abount unused ActiveX Controls box to Remove, avoid using control does not initialize the design form not ,
Finally, to dynamically create
 'Form2 
Option Explicit

Private Sub Command1_Click ()
Dim DGRD As MSDataGridLib. DataGrid
Set DGRD=Form1. Controls. The Add (" MsDatagridLib. Datagrid ", "DataGrid1," Form1)
DGRD. Visible=True
End Sub

CodePudding user response:

Won't change, that will make me the code A Form1 A function A (), another form Form1. Direct call function A (), other what all need not change

CodePudding user response:

Drag a DataGrid control to the form and set the Visible to False, the Index is 0, the Name for DataGrids
Want to add the Load DataGrids (1) : DataGrids (1). The Visible=True
  • Related