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
  1. Home
  2. General Programming
  3. C#
  4. Auto adjust column width

Auto adjust column width

Scheduled Pinned Locked Moved C#
2 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.
  • V Offline
    V Offline
    vcorn
    wrote on last edited by
    #1

    how do we get our column width auto adjusted to fit the length of the column header text when it's displayed in dataGrid. Thanks:-D

    H 1 Reply Last reply
    0
    • V vcorn

      how do we get our column width auto adjusted to fit the length of the column header text when it's displayed in dataGrid. Thanks:-D

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      There is no automatic adjustment for the DataGrid like there is for the ListView (not data-bindable). You must either guess at design-time, or when the DataGrid is loading, enumerate the DataGrid.TableStyles collection property, and enumerate each's GridColumnStyles collection property. Get the text and use Graphics.MeasureString using the Font property of the DataGrid. Set the current column's Width accordingly. This only works when 1) you're using explicitly defined table and column styles before data is bound, or 2) after data is bound to the DataGrid.

      Microsoft MVP, Visual C# My Articles

      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