Column width in DataGrid

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jaime Lucci

    #1

    Column width in DataGrid

    Hi, how've you been?

    How can I do to set the column width of a datagrid to fix the width of the
    text in each column?

    Thanks.

    Jaime Lucci
    jaimelucci@hotm ail.com


  • Herfried K. Wagner [MVP]

    #2
    Re: Column width in DataGrid

    "Jaime Lucci" <jaimelucci@hot mail.com> schrieb:[color=blue]
    > How can I do to set the column width of a datagrid to fix the width of the
    > text in each column?[/color]

    5.52 How can I autosize a column in my datagrid?
    <URL:http://www.syncfusion. com/FAQ/WindowsForms/FAQ_c44c.aspx#q 877q>

    --
    M S Herfried K. Wagner
    M V P <URL:http://dotnet.mvps.org/>
    V B <URL:http://classicvb.org/petition/>

    Comment

    • Jim Underwood

      #3
      Re: Column width in DataGrid

      This code will not solve your problem entirely, but may put you on the right
      track. In my case I had a dozen different data grids and didn't want to
      specify the names and widths of every collumn in every one of them so I just
      created a function to set all of the collumns to a longer width. It is much
      simpler to maintain but doesnt give you as much flexibility.

      Public Shared Sub SetTableStyle(B yRef MyDataGrid As DataGrid)

      '************** *************** *************** *************** ************
      ' Public method
      ' called by all forms using datagrids
      ' defines consistent table styles in one place

      '************** *************** *************** *************** ************
      Dim objTableStyle As New DataGridTableSt yle
      objTableStyle.A lternatingBackC olor = System.Drawing. Color.OldLace
      'set every other datagrid line to a seperate color to make it easier to read
      objTableStyle.P referredColumnW idth = 150
      MyDataGrid.Tabl eStyles.Add(obj TableStyle)
      End Sub

      You can also specify individual collumns, identified by the collumn name in
      your dataset. This can be done programatically , or through the TableStyles
      Collectin in the designer.


      "Jaime Lucci" <jaimelucci@hot mail.com> wrote in message
      news:Onzw0ww2FH A.2196@tk2msftn gp13.phx.gbl...[color=blue]
      > Hi, how've you been?
      >
      > How can I do to set the column width of a datagrid to fix the width of the
      > text in each column?
      >
      > Thanks.
      >
      > Jaime Lucci
      > jaimelucci@hotm ail.com
      >
      >[/color]


      Comment

      Working...