Grid columns

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

Is there a way to freeze grid column widths so users can not change them
interactively?

Thanks

Regards
 
There is a TableStyles property of the grid... Each table style contains
DataGridColumnStyle objects for each column.

There is no property/method to fix the width, but there is a "WidthChanged"
event you can monitor. In it, just keep setting the width back to the value
you want. Not very clean, but don't know another way.

Why prevent resizing of a column? You don't want them to see all the data in
it?! If they aren't supposed to see the column at all (width zero); then
make it invisible as Ravikanth suggests.
 
Users will want to change column width's, and if you
don't let them, they'll consider it obnoxious. It's too
ingrained in folks these days.

I totally agree with the other two posts.

Either hide it totally...http://www.c-
sharpcorner.com/FAQ/Part1Howdos.asp

Or use a query on the DB side to limit the data from
coming in at all. For instance, if you pull back a
DataTime and you don't want time, specify that in your
query.....NEt will acknoledge its type if you use Parse().

Trapping the resize event is the 3:33t programmer way of
doing it and it's an excellent method if you Really need
to stop it. Similarly,you could subclass the grid, and
override column resizing in your class.

However, a lot of people spent a lot of time building
that functionality into the grid and users from people
who use Enterprise Manager to Excel and everyone in
between are used to it.... I don't know that I'd put a
lot of effort into reducing functionality. Whatever the
reason is for not allowing the resize, there's probably
another way to get there without hitting the grid.

BTW, you posted b/c you need a solution, not a lecture,
so if it sounded like one....didn't mean to. The last
thing developers usually want to here is 'why do you want
to do that'. If you need help with the subclassing, SQL
or trapping the event, I'll be glad to assist.

Good Luck,

Bill


Cordially,

W.G. Ryan
(e-mail address removed)
www.knowdotnet.com
 
Back
Top