Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. db grid col width

db grid col width

Scheduled Pinned Locked Moved Visual Basic
helpcssdatabase
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Paps2
    wrote on last edited by
    #1

    Hi all, I am trying to fix teh col width of my datagrid but I get an error @ dbgrd.GridColumnStyles(0).Width = 50 The error Msg is : An unhadled exception of type 'System.ArgumentOutOfRangeEception' Occured in mscorlib.dll. Addional Information: Index was out of range. Must be non negative and less than the size of the collection. Code: With ds.Tables("Ord1") Dim iCount As Integer Dim nRow As Data.DataRow For iCount = 0 To .Rows.Count - 1 nRow = objDT.NewRow() nRow(0) = CType(.Rows(iCount).Item(0), String) nRow(1) = CType(.Rows(iCount).Item(1), String) nRow(2) = CType(.Rows.Item(iCount).Item(2), Long) objDT.Rows.Add(nRow) Next Dim dbgrd1 As DataGridTableStyle = New DataGridTableStyle() dbGrid1.DataSource = objDT dbGrid1.ReadOnly = True Dim dbgrd As DataGridTableStyle = New DataGridTableStyle() dbgrd.MappingName = "Ord1" dbGrid1.TableStyles.Add(dbgrd) dbgrd.GridColumnStyles(0).Width = 50 dbgrd.GridColumnStyles(1).Width = 500 dbgrd.GridColumnStyles(2).Width = 500 can some one help. Tnx

    J 1 Reply Last reply
    0
    • P Paps2

      Hi all, I am trying to fix teh col width of my datagrid but I get an error @ dbgrd.GridColumnStyles(0).Width = 50 The error Msg is : An unhadled exception of type 'System.ArgumentOutOfRangeEception' Occured in mscorlib.dll. Addional Information: Index was out of range. Must be non negative and less than the size of the collection. Code: With ds.Tables("Ord1") Dim iCount As Integer Dim nRow As Data.DataRow For iCount = 0 To .Rows.Count - 1 nRow = objDT.NewRow() nRow(0) = CType(.Rows(iCount).Item(0), String) nRow(1) = CType(.Rows(iCount).Item(1), String) nRow(2) = CType(.Rows.Item(iCount).Item(2), Long) objDT.Rows.Add(nRow) Next Dim dbgrd1 As DataGridTableStyle = New DataGridTableStyle() dbGrid1.DataSource = objDT dbGrid1.ReadOnly = True Dim dbgrd As DataGridTableStyle = New DataGridTableStyle() dbgrd.MappingName = "Ord1" dbGrid1.TableStyles.Add(dbgrd) dbgrd.GridColumnStyles(0).Width = 50 dbgrd.GridColumnStyles(1).Width = 500 dbgrd.GridColumnStyles(2).Width = 500 can some one help. Tnx

      J Offline
      J Offline
      Jim Matthews
      wrote on last edited by
      #2

      hi paps, you're not actually instantiating any GridColumnStyles in your code. you're just trying to set the width of empty array elements. (GridColumnStyles(0), GridColumnStyles(1), GridColumnStyles(2) etc.) this is the raeson for the exception. you can try doing this with the vs.net designer as well. just look at the TableStyles property of the datagrid from the properties window. you can set this up so that it's created in the initialization routine of the form rather than manually writing the code for it. take advantage of the code generation module and save yourself a case of carpal tunnels syndrome. :) hope this helps.


      -jim

      P 2 Replies Last reply
      0
      • J Jim Matthews

        hi paps, you're not actually instantiating any GridColumnStyles in your code. you're just trying to set the width of empty array elements. (GridColumnStyles(0), GridColumnStyles(1), GridColumnStyles(2) etc.) this is the raeson for the exception. you can try doing this with the vs.net designer as well. just look at the TableStyles property of the datagrid from the properties window. you can set this up so that it's created in the initialization routine of the form rather than manually writing the code for it. take advantage of the code generation module and save yourself a case of carpal tunnels syndrome. :) hope this helps.


        -jim

        P Offline
        P Offline
        Paps2
        wrote on last edited by
        #3

        Thanks a bunch.

        1 Reply Last reply
        0
        • J Jim Matthews

          hi paps, you're not actually instantiating any GridColumnStyles in your code. you're just trying to set the width of empty array elements. (GridColumnStyles(0), GridColumnStyles(1), GridColumnStyles(2) etc.) this is the raeson for the exception. you can try doing this with the vs.net designer as well. just look at the TableStyles property of the datagrid from the properties window. you can set this up so that it's created in the initialization routine of the form rather than manually writing the code for it. take advantage of the code generation module and save yourself a case of carpal tunnels syndrome. :) hope this helps.


          -jim

          P Offline
          P Offline
          Paps2
          wrote on last edited by
          #4

          When I set the prefered col width to 200 all the other columns too take the same width. How do I specify the 2nd col with a different width. Tnx

          J 2 Replies Last reply
          0
          • P Paps2

            When I set the prefered col width to 200 all the other columns too take the same width. How do I specify the 2nd col with a different width. Tnx

            J Offline
            J Offline
            Jim Matthews
            wrote on last edited by
            #5

            hi paps, the preferred width property is on the tablestyle object. this will set the width of any columnstyle in the tablestyles gridcolumnstyles property that has a width value of 0. if you set the width property of the columnstyle, the width of that column will be set accordingly. hope this helps.


            -jim

            1 Reply Last reply
            0
            • P Paps2

              When I set the prefered col width to 200 all the other columns too take the same width. How do I specify the 2nd col with a different width. Tnx

              J Offline
              J Offline
              Jim Matthews
              wrote on last edited by
              #6

              hi paps, the gridcolumnstyles property belongs to the tablestyles property of the datagrid. so if you are doing this through the designer, have a look at the properties of the datagrid, find the tablestyles property and click the ellipsis button [...]. this should open the tablestyles editor dialog. next look for the columnstyles property in this dialog and click the ellipis button. this will open the columnstyles editor. hope this helps.


              -jim

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups