[RESOLVED] datagrid in vb6-VBForums
Results 1 to 21 of 21

Thread: [RESOLVED] datagrid in vb6

  1. #1

    Thread Starter
    Member
    Join Date
    May 2008
    Posts
    50

    Resolved [RESOLVED] datagrid in vb6

    i have a datagrid in form load,
    how can i change the columns width and height ?
    i want to change with different size each column and not all the same
    (with code if you can)

  2. #2
    Super Moderator Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    11,928

    Re: datagrid in vb6

    Something like this?

    vb Code:
    1. Private Sub Form_Load()
    2.     With DataGrid1
    3.         .Columns(0).width = '<~~ your value
    4.         .Columns(1).width = '<~~ your value
    5.         '~~> and so on...
    6.     End With
    7. End Sub
    The poster formerly known as koolsid
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved

    Microsoft MVP: 2011 - Till Date IMP Links : Acceptable Use Policy, FAQ

    MyGear:
    Sony VGN-FZ27G with a triple boot between (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008) and (Win7+Office 2010+VS2010) || Sony VPCCB-45FN with a Win7+Office 2010+VS2010. VM: (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008), (Win8+Office 2010+VS2012) || Mac Book Pro (10.6.8) with Office 2011

  3. #3

    Thread Starter
    Member
    Join Date
    May 2008
    Posts
    50

    Re: datagrid in vb6

    Quote Originally Posted by koolsid View Post
    Something like this?

    vb Code:
    1. Private Sub Form_Load()
    2.     With DataGrid1
    3.         .Columns(0).width = '<~~ your value
    4.         .Columns(1).width = '<~~ your value
    5.         '~~> and so on...
    6.     End With
    7. End Sub
    DataGrid.Columns(0).Width = "1000"
    DataGrid.Columns(1).Width = "2000"
    DataGrid.Columns(2).Width = "3000"

    i get an error
    "subscript out of range "
    why?????

  4. #4
    Super Moderator Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    11,928

    Re: datagrid in vb6

    1) Which line gives you the error?
    2) How many columns are there in the Grid?
    3) Also the value of the width is not a string. It should be

    DataGrid.Columns(0).Width = 1000
    The poster formerly known as koolsid
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved

    Microsoft MVP: 2011 - Till Date IMP Links : Acceptable Use Policy, FAQ

    MyGear:
    Sony VGN-FZ27G with a triple boot between (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008) and (Win7+Office 2010+VS2010) || Sony VPCCB-45FN with a Win7+Office 2010+VS2010. VM: (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008), (Win8+Office 2010+VS2012) || Mac Book Pro (10.6.8) with Office 2011

  5. #5

    Thread Starter
    Member
    Join Date
    May 2008
    Posts
    50

    Re: datagrid in vb6

    in line DataGrid.Columns(2).Width = "3000" i get the error
    i have 2 columns , but i want 27 columns as default
    i made the change in " " but also the same error

  6. #6
    Super Moderator Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    11,928

    Re: datagrid in vb6

    If you don't have a column, you cannot set a width to it

    Create columns in design/runtime and then set the width to it...
    The poster formerly known as koolsid
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved

    Microsoft MVP: 2011 - Till Date IMP Links : Acceptable Use Policy, FAQ

    MyGear:
    Sony VGN-FZ27G with a triple boot between (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008) and (Win7+Office 2010+VS2010) || Sony VPCCB-45FN with a Win7+Office 2010+VS2010. VM: (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008), (Win8+Office 2010+VS2012) || Mac Book Pro (10.6.8) with Office 2011

  7. #7

    Thread Starter
    Member
    Join Date
    May 2008
    Posts
    50

    Re: datagrid in vb6

    Quote Originally Posted by koolsid View Post
    If you don't have a column, you cannot set a width to it

    Either create columns in design/runtime and then set the width to it...
    how can i do this ? (create more columns)

  8. #8
    Super Moderator Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    11,928

    Re: datagrid in vb6

    Before I answer that question... What are you storing in Datagrid? Where is the data coming from?
    The poster formerly known as koolsid
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved

    Microsoft MVP: 2011 - Till Date IMP Links : Acceptable Use Policy, FAQ

    MyGear:
    Sony VGN-FZ27G with a triple boot between (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008) and (Win7+Office 2010+VS2010) || Sony VPCCB-45FN with a Win7+Office 2010+VS2010. VM: (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008), (Win8+Office 2010+VS2012) || Mac Book Pro (10.6.8) with Office 2011

  9. #9

    Thread Starter
    Member
    Join Date
    May 2008
    Posts
    50

    Re: datagrid in vb6

    Quote Originally Posted by koolsid View Post
    Before I answer that question... What are you storing in Datagrid? Where is the data coming from?
    i have an adodb connection,recordset
    and i have a sub called createdummybase which creates a database
    and the fields of that database shows on the datagrid

  10. #10
    Super Moderator Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    11,928

    Re: datagrid in vb6

    Is that an Access database?
    The poster formerly known as koolsid
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved

    Microsoft MVP: 2011 - Till Date IMP Links : Acceptable Use Policy, FAQ

    MyGear:
    Sony VGN-FZ27G with a triple boot between (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008) and (Win7+Office 2010+VS2010) || Sony VPCCB-45FN with a Win7+Office 2010+VS2010. VM: (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008), (Win8+Office 2010+VS2012) || Mac Book Pro (10.6.8) with Office 2011

  11. #11

    Thread Starter
    Member
    Join Date
    May 2008
    Posts
    50

    Re: datagrid in vb6

    Quote Originally Posted by koolsid View Post
    Is that an Access database?
    yeap

  12. #12
    Lively Member
    Join Date
    Jan 2005
    Posts
    76

    Re: datagrid in vb6

    * .ColWidth() requires number, take out the quotes.
    * .ColWidth() is in twips. If you want to have column width proportional to the width then write
    .ColWidth(2) = .Width * 0.1 ' width of column number 2 is 10&#37; of the width.

  13. #13
    Lively Member
    Join Date
    Jan 2005
    Posts
    76

    Re: datagrid in vb6

    To set number of columns use
    .Cols = 10 ' 10 columns, numbered 0..9

  14. #14

    Thread Starter
    Member
    Join Date
    May 2008
    Posts
    50

    Re: datagrid in vb6

    Quote Originally Posted by kiymik View Post
    To set number of columns use
    .Cols = 10 ' 10 columns, numbered 0..9
    DataGrid.Col exists
    DataGrid.Cols does not exists

  15. #15
    Super Moderator Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    11,928

    Re: datagrid in vb6

    Hi I am writing a small tutorial for you on how to use datagrid with access database.... I will upload the same in another hour or so... I am at the office and I need to multitask
    The poster formerly known as koolsid
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved

    Microsoft MVP: 2011 - Till Date IMP Links : Acceptable Use Policy, FAQ

    MyGear:
    Sony VGN-FZ27G with a triple boot between (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008) and (Win7+Office 2010+VS2010) || Sony VPCCB-45FN with a Win7+Office 2010+VS2010. VM: (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008), (Win8+Office 2010+VS2012) || Mac Book Pro (10.6.8) with Office 2011

  16. #16

    Thread Starter
    Member
    Join Date
    May 2008
    Posts
    50

    Re: datagrid in vb6

    Quote Originally Posted by koolsid View Post
    Hi I am writing a small tutorial for you on how to use datagrid with access database.... I will upload the same in another hour or so... I am at the office and I need to multitask
    ok, thanks
    where are you going to upload it?

  17. #17
    Super Moderator Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    11,928

    Re: datagrid in vb6

    Here in my next post

    Give me another half an hour... just came back from office....
    The poster formerly known as koolsid
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved

    Microsoft MVP: 2011 - Till Date IMP Links : Acceptable Use Policy, FAQ

    MyGear:
    Sony VGN-FZ27G with a triple boot between (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008) and (Win7+Office 2010+VS2010) || Sony VPCCB-45FN with a Win7+Office 2010+VS2010. VM: (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008), (Win8+Office 2010+VS2012) || Mac Book Pro (10.6.8) with Office 2011

  18. #18
    Super Moderator Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    11,928

    Re: datagrid in vb6

    Phew here it is....

    Hope this helps....
    Attached Files Attached Files
    The poster formerly known as koolsid
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved

    Microsoft MVP: 2011 - Till Date IMP Links : Acceptable Use Policy, FAQ

    MyGear:
    Sony VGN-FZ27G with a triple boot between (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008) and (Win7+Office 2010+VS2010) || Sony VPCCB-45FN with a Win7+Office 2010+VS2010. VM: (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008), (Win8+Office 2010+VS2012) || Mac Book Pro (10.6.8) with Office 2011

  19. #19

    Thread Starter
    Member
    Join Date
    May 2008
    Posts
    50

    Re: datagrid in vb6

    Quote Originally Posted by koolsid View Post
    Phew here it is....

    Hope this helps....
    thank you very much,for your time
    you helped me
    very good mini tutorial

  20. #20
    Super Moderator Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    11,928

    Re: datagrid in vb6

    Glad to be of help

    Do remember to mark your thread resolved Check my signature on how to do it...
    The poster formerly known as koolsid
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved

    Microsoft MVP: 2011 - Till Date IMP Links : Acceptable Use Policy, FAQ

    MyGear:
    Sony VGN-FZ27G with a triple boot between (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008) and (Win7+Office 2010+VS2010) || Sony VPCCB-45FN with a Win7+Office 2010+VS2010. VM: (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008), (Win8+Office 2010+VS2012) || Mac Book Pro (10.6.8) with Office 2011

  21. #21
    Lively Member
    Join Date
    Jan 2005
    Posts
    76

    Re: [RESOLVED] datagrid in vb6

    Sorry, it was for flexgrid...

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.