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. winforms: aligning of column headers

winforms: aligning of column headers

Scheduled Pinned Locked Moved C#
csharpwinformshelpquestion
4 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.
  • T Offline
    T Offline
    troels_sorensen
    wrote on last edited by
    #1

    Hi. Is there any way to center-align columnheaders in a datagrid while the text in the rows of the column is still rigth-aligned? I found out using datagridTextBox.Alignment, but this aligns both header AND text in the rows... any help?

    H 1 Reply Last reply
    0
    • T troels_sorensen

      Hi. Is there any way to center-align columnheaders in a datagrid while the text in the rows of the column is still rigth-aligned? I found out using datagridTextBox.Alignment, but this aligns both header AND text in the rows... any help?

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

      You could create your own DataGridColumnStyle derivatives and ignore the Alignment property. Just derive from the existing ones like DataGridTextBoxColumn and DataGridBoolColumn to avoid having to implement the rest of the behavior.

      -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

      T 1 Reply Last reply
      0
      • H Heath Stewart

        You could create your own DataGridColumnStyle derivatives and ignore the Alignment property. Just derive from the existing ones like DataGridTextBoxColumn and DataGridBoolColumn to avoid having to implement the rest of the behavior.

        -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

        T Offline
        T Offline
        troels_sorensen
        wrote on last edited by
        #3

        but the columnstyke also aligns both the text and the headers, right? So unless i override the paint event, I can't do what i want....

        H 1 Reply Last reply
        0
        • T troels_sorensen

          but the columnstyke also aligns both the text and the headers, right? So unless i override the paint event, I can't do what i want....

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

          In the override for DataGridColumnStyle.Alignment, try returning HorizontalAlignment.Left. The default painting procedure should use that to paint the text; otherwise, yes, you will have to do the text painting yourself (but that is pretty easy to do). See Graphics.MeasureString and Graphics.DrawString for more information.

          -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

          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