I want to explain this as best as I can. I have a Webgrid with a certain amount of columns. What I want is for the columns to adjust to the size of the larges开发者_运维百科t string within each column, where the total of all width of columns does not exceed the width of the webgrid. At the same time however if the width of all columns is less than the width of the webgrid I want each column to adjust proportionately so that the total of columns widths equal the width of the webgrid.
Example:
grid width = 100
On Initial Data Load: col1 max width = 25 col2 max width = 35 col3 max width = 20 col total = 80
still 20(meas) left in the grid.
After all loading without manually setting column widths: col total needs to = 100
Can anyone help me with this logic?
There is a setting on the columns to set the width to be that of the longest string in it. However I don't know what it will do if the total desired widths are beyond the total width of your grid. It may just add a scroll bar at the bottom so you can scroll to each column (not what you want to happen).
The two settings you will want to look at is one for the columns themselves and one for the grid.
ColumnAutoSizeMode.AllRowsInBand
or use "ColumnAutoSizeMode.VisibleRows" if you want the column to just resize on the currently visible rows
AutoFitStyle.ResizeAllColumns
I was able to create a class that automatically adjust visible columns and fit them inside a grid.
精彩评论