Auto adjust column width
C#
2
Posts
2
Posters
0
Views
1
Watching
-
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
There is no automatic adjustment for the
DataGrid
like there is for theListView
(not data-bindable). You must either guess at design-time, or when theDataGrid
is loading, enumerate theDataGrid.TableStyles
collection property, and enumerate each'sGridColumnStyles
collection property. Get the text and useGraphics.MeasureString
using theFont
property of theDataGrid
. Set the current column'sWidth
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 theDataGrid
.Microsoft MVP, Visual C# My Articles