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. how to prevent changing columns' width in datagrid?

how to prevent changing columns' width in datagrid?

Scheduled Pinned Locked Moved C#
tutorialquestion
4 Posts 3 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.
  • W Offline
    W Offline
    wangier
    wrote on last edited by
    #1

    how to prevent changing columns' width in datagrid?

    H G 2 Replies Last reply
    0
    • W wangier

      how to prevent changing columns' width in datagrid?

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

      You could derive from DataGridColumnStyle (or one of the derivative classes to avoid extra work) and override the Width property so that the set accessor does nothing. You'll have to have an internal property or a param in the constructor so you can set the initial width, though, which you can do by setting base.Width. This works in a quick test but still allows the user to drag the splitters (just doesn't actually change the width). Upon inspection, the members you'd need to override are both private and are not virtual, nor do they use anything relevent that is overridable. About the only thing I can think of is to override WndProc and handle mouse messages over the column header (which you can get the bounds of through various properties), not passing those to the base.WndProc.

      -----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-----

      W 1 Reply Last reply
      0
      • W wangier

        how to prevent changing columns' width in datagrid?

        G Offline
        G Offline
        Guillermo Rivero
        wrote on last edited by
        #3

        Take a look at www.syncfusion.com[^] and go to FAQ. Free your mind...

        1 Reply Last reply
        0
        • H Heath Stewart

          You could derive from DataGridColumnStyle (or one of the derivative classes to avoid extra work) and override the Width property so that the set accessor does nothing. You'll have to have an internal property or a param in the constructor so you can set the initial width, though, which you can do by setting base.Width. This works in a quick test but still allows the user to drag the splitters (just doesn't actually change the width). Upon inspection, the members you'd need to override are both private and are not virtual, nor do they use anything relevent that is overridable. About the only thing I can think of is to override WndProc and handle mouse messages over the column header (which you can get the bounds of through various properties), not passing those to the base.WndProc.

          -----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-----

          W Offline
          W Offline
          wangier
          wrote on last edited by
          #4

          thanks!

          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