how to prevent changing columns' width in datagrid?
-
You could derive from
DataGridColumnStyle
(or one of the derivative classes to avoid extra work) and override theWidth
property so that theset
accessor does nothing. You'll have to have aninternal
property or a param in the constructor so you can set the initial width, though, which you can do by settingbase.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 overrideWndProc
and handle mouse messages over the column header (which you can get the bounds of through various properties), not passing those to thebase.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-----
-
Take a look at www.syncfusion.com[^] and go to FAQ. Free your mind...
-
You could derive from
DataGridColumnStyle
(or one of the derivative classes to avoid extra work) and override theWidth
property so that theset
accessor does nothing. You'll have to have aninternal
property or a param in the constructor so you can set the initial width, though, which you can do by settingbase.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 overrideWndProc
and handle mouse messages over the column header (which you can get the bounds of through various properties), not passing those to thebase.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-----