Results 1 to 9 of 9

Thread: [RESOLVED] How to add more 2 columns to DataGrid ?

  1. #1

    Thread Starter
    Member
    Join Date
    May 2009
    Posts
    55

    Resolved [RESOLVED] How to add more 2 columns to DataGrid ?

    DataGrid came by default with two columns only (0, 1)
    So, how can I add more than 2 columns to a DataGrid ?

  2. #2
    Hyperactive Member jp26198926's Avatar
    Join Date
    Sep 2008
    Location
    General Santos City, Philippines
    Posts
    310

    Re: How to add more 2 columns to DataGrid ?

    DataGrid1.Columns.Add 2
    "More Heads are Better than One"

  3. #3

    Thread Starter
    Member
    Join Date
    May 2009
    Posts
    55

    Re: How to add more 2 columns to DataGrid ?

    Quote Originally Posted by jp26198926 View Post
    DataGrid1.Columns.Add 2
    I used it like the following code:
    VB Code:
    1. DataGrid1.Columns.Add 5
    2. DataGrid1.Columns(0).Caption = "111"
    3. DataGrid1.Columns(1).Caption = "222"
    4. DataGrid1.Columns(2).Caption = "333"
    5. DataGrid1.Columns(3).Caption = "444"
    6. DataGrid1.Columns(4).Caption = "555"
    I got this error messege:
    Runtime error '424':
    Object required
    Last edited by alMubarmij; Oct 7th, 2009 at 06:24 AM.

  4. #4
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,170

    Re: How to add more 2 columns to DataGrid ?

    try like this
    Code:
    For i = 0 To 4
        DataGrid1.Columns.Add(i).Caption = "Column " & i
    Next
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


  5. #5
    Hyperactive Member jp26198926's Avatar
    Join Date
    Sep 2008
    Location
    General Santos City, Philippines
    Posts
    310

    Re: How to add more 2 columns to DataGrid ?

    DataGrid.Columns(0).....

    should be..
    DataGrid1.Columns(0)....


    Code:
    Dim i As Integer
    
    For i = 2 To 4
        DataGrid1.Columns.Add i
    Next i
    
    DataGrid1.Columns(0).Caption = "111"
    DataGrid1.Columns(1).Caption = "222"
    DataGrid1.Columns(2).Caption = "333"
    DataGrid1.Columns(3).Caption = "444"
    DataGrid1.Columns(4).Caption = "555"
    "More Heads are Better than One"

  6. #6

    Thread Starter
    Member
    Join Date
    May 2009
    Posts
    55

    Thumbs up Re: How to add more 2 columns to DataGrid ?

    This code will work correctly:
    VB Code:
    1. DataGrid1.ColumnHeaders = True
    2.  
    3. For i = 0 To 4
    4.     DataGrid1.Columns.Add(i)
    5. Next
    6.  
    7. DataGrid1.Columns(0).Caption = "Header-1"
    8. DataGrid1.Columns(1).Caption = "Header-2"
    9. DataGrid1.Columns(2).Caption = "Header-3"
    10. DataGrid1.Columns(3).Caption = "Header-4"
    11. DataGrid1.Columns(4).Caption = "Header-5"
    I was use "DataGrid" not "DataGrid1".
    Thanks for all.
    Last edited by alMubarmij; Oct 7th, 2009 at 06:31 AM.

  7. #7

    Thread Starter
    Member
    Join Date
    May 2009
    Posts
    55

    Re: How to add more 2 columns to DataGrid ?

    The main problem now that "DataField" property does not work:
    VB Code:
    1. DataGrid1.Columns(0).DataField = "Field1"
    2. DataGrid1.Columns(1).DataField = "Field2"
    3. DataGrid1.Columns(2).DataField = "Field3"
    4. DataGrid1.Columns(3).DataField = "Field4"
    5. DataGrid1.Columns(4).DataField = "Field5"

    I got now all columns in my query not only that five !

    Can I customize the number of columns in design mode (not in runtime) ?

  8. #8
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,170

    Re: How to add more 2 columns to DataGrid ?

    u can add columns in design time aslo, right click -> edit, again right click -> insert
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


  9. #9

    Thread Starter
    Member
    Join Date
    May 2009
    Posts
    55

    Re: How to add more 2 columns to DataGrid ?

    Thank you, it's working.

Tags for this Thread

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