1,105,546 Community Members

DataGrid column width in runtime

Member Avatar
weeraa
Junior Poster in Training
97 posts since Oct 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Im developing application using ASP.net + VB.net
Now i want to change column width at run time. But in run time it doesn't work.

This is what i did up to now.
data bind in form load like this.

myGrid.datasource = myDataSet.table(0)
myGrid.databind()

In here dataset come properly.

in grid data bound event

 If e.Row.RowType = DataControlRowType.Header Then

Dim cell As TableCell = e.Row.Cells(1)
            cell.Width = New Unit(200) 'I added "200px" instead of 200. But it didn't work.
cell.text = "abc" 'This is working. It is show the header as abc

end if

in above code i added (as an experiment) cell.wrap = false and cell.wrap = true. that code also not effected.
There is no any error. But width doesnt work.

LastMitch
Deleted Member
 
0
 

There is no any error. But width doesnt work.

Why used cell.wrap?

cell.Width = New Unit(200) 'I added "200px" instead of 200. But it didn't work.

I'm not familiar with VB. Since you are creating an application using ASP.net + VB.net you should used something more flexible than actually giving it a 200px. Used this instead:

http://msdn.microsoft.com/en-us/library/System.Windows.Forms.DataGridView.AutoResizeRowHeadersWidth.aspx

Member Avatar
weeraa
Junior Poster in Training
97 posts since Oct 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
1
 

I added style="table-layout:fixed" to the ASP grid code. Now the problem is ok.

Question Answered as of 10 Months Ago by LastMitch
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: