CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 1999
    Posts
    91

    How to create a DataGrid on running time ?

    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



  2. #2
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: How to create a DataGrid on running time ?


    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

  3. #3
    Join Date
    Aug 2000
    Location
    NY, USA
    Posts
    632

    Re: How to create a DataGrid on running time ?

    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


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured