Link to home
Create AccountLog in
Avatar of mpdalton

asked on

GridView Column Width

we have a gridview that we are manually setting up the columns in.

the column widths are defined by the user, but occasionly they specify a width that is smaller than required for the heading text.

the gridview automatically resizes the column and makes the other columns slightly smaller to fix this up.

the problem is that we dynamically add controls above and below the gridview to filtering and totalling so when the gridview is automatically resized the controls dont match up.

when we ask the column width, even after calling the databind method, it returns the width we set it as, not what it has been resized too.

how do i get the real column width.

note: when i talk about columns, i'm referrring to DataControlField's which are what dataview's call columns.
Avatar of aki4u

How is width set? By %? What are default settings for all columns (% or px)?
Avatar of mpdalton


they are in px

Dim dgc As DataGridColumnStyle
   dgc = DataGrid1.TableStyles(0).GridColumnStyles("id")
   dgc.Width = 500
Avatar of Solar_Flare

Link to home
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
hi solar_flare, you are right, the html is correct when i view the source, so it's the brower that is causing the problem.

any ideas how to override this behaviour so it maybe auto truncates the field or wraps it ? the column heading is already set to wrap but this only works when there are multiple words to a heading not one long word.
browsers would not be capable of truncating or wahtever, you would have to rename the columns so they are short enought to fit or change the font size

for each c as datacolumn in yourDatatable.Columns
    if c.ColumnName.Length > 10 then c.columnName = c.ColumnName.Substring(0, 10)


something like that in your codebehind would stop the headings being too long, butmight make it look ugly?

maybe resize the font of the header based on the length of the longest word so it wraps correctly? this would be more coding but might look better.
thanks for your help solar_flare. now that i know the limitiations of the browser i can let the project sponsor know that users will just have to check during table setup that the field width is wide enough.