Click to See Complete Forum and Search --> : How to create a DataGrid on running time ?
SUNRISE
March 22nd, 2001, 11:32 PM
Hi, everyone :
If I want create a Label on running time .
I can code like under :
Dim Label1 as Label
set Label1 = Controls.Add("VB.Label", "Label1")
but If I want create a "DataGrid" on running time ,
Can you tell me how to code ?
Thanks very much
John G Duffy
March 23rd, 2001, 10:37 AM
private Sub Form_Load()
Dim DBG as DataGrid
set DBG = Controls.Add("MSDATAGRIDLIB.datagrid", "DbGrid")
DBG.Move 0, 0, 1000, 10000
DBG.Visible = true
End Sub
John G
vchapran
March 23rd, 2001, 10:47 AM
Do the same as you do with label. Some special requirements:
1.Add a reference to the control through Components
2. If you did not place any grid at design time, then go to project properties, and uncheck "Remove information about unused ActiveX controls"
3. Place Grid on your form just to find how it's called - for Microsoft DataBound Grid Control it's DBGrid.
4.Run RegEdit and make search for DBGrid.
5. When it's found, open ProgID hive and read Value - for our case it's "MSDBGrid.DBGrid"
Now do the same as for label, create it, set properties, make it visible and so on.
Example of code:
private Sub Command1_Click()
Dim Label1 as Label
Dim Grid as DBGrid
set Label1 = Controls.Add("VB.Label", "Label1")
set Grid = Controls.Add("MSDBGrid.DBGrid", "Grid1")
With Label1
.Visible = true
.Left = 100
.Top = 100
.Width = 500
.Caption = "Label"
End With
With Grid
.Visible = true
.Width = 3500
.Height = 1500
End With
End Sub
HTH
Vlad
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.