This is from the ControlResized event of a DataGrid. I remember this because without the random numbers only the last column would be resized:
colWidths contain the column widths, which are saved in the preferences.
dim BeforeWidth as Integer = ColWidths.total
dim currentWidth as Integer = me.Width - getScrollbarWidth
dim theWidth as Integer
dim thePercent as Double = currentWidth/BeforeWidth
for currentCol as Integer = 1 to me.Cols
me.Column(currentCol).Width = me.Column(currentCol).Width * thePercent
theWidth = theWidth + me.Column(currentCol).Width
next
'can't simply adjust the last column, the percentage values are so small that only the last column would get broader
'the random number gives the rest to all columns well randomly
dim theRandom as new Random
dim RandCol as Integer = theRandom.InRange(1, me.Cols)
me.Column(RandCol).Width = me.Column(RandCol).Width + (me.Width - theWidth - getScrollbarWidth)