Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GridView Column Width change in code

Status
Not open for further replies.

Trusts

Programmer
Feb 23, 2005
268
US
Hi all,

I have an app in which I need to change a gridview column width on the fly, depending on other actions the user has taken. These actions are not known ahead of time.

I have been trying variations of width settings, but nothing seems to work. The text values in the column average about 15 characters, and this seems to force the column to stay to a width that displays the text. Code:

GridView_Instruments.Columns(2).HeaderText = ""
GridView_Instruments.Columns(2).HeaderStyle.Width = UnitType.Pixel
GridView_Instruments.Columns(2).ItemStyle.Width = 1

GridView_Instruments.Columns(2).ItemStyle.Width = UnitType.Pixel
GridView_Instruments.Columns(2).ItemStyle.Width = 1


As you can see I've tried both resizing the header and the column. No luck.

On a side note my real need is just to hide the column - taht works, but when they edit the row, the update bombs since the value in the column is taken as null. Therefore I figured 1 pixel is pretty close to not visible.

Any ideas??

Thanks,

KB
 
Can't you hide the column like this?
Code:
    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
        e.Row.Cells(0).Visible = False
    End Sub


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top