When you’re dealing with Infragistics WebDataGrid and want to manipulate appearance of individual columns – there’s a handy Columns
collection for that. Unfortunately it’s available only if you define columns at design time or add columns to it in code-behind. If your grid features autogenerated columns – the collection will be empty.
There’s a way to derive column info tho – and can be done from grid row. The example below uses grid’s PreRender
event to capture first row from which columns are derived and their width set:
Protected Sub xmyGrid_PreRender(sender As Object, e As EventArgs) Handles myGrid.PreRender Dim oGrid As GridControls.ContainerGrid Dim oRow As GridControls.ContainerGridRecord oGrid = sender oRow = oGrid.Rows(0) If oRow IsNot Nothing Then InitGridColumns(oRow) 'passing 1st grid row to helper sub End If End Sub Sub InitGridColumns(i_oRow As GridControls.ContainerGridRecord) Dim oGridCol As GridControls.BoundDataField 'looping thru row cells For I As Integer = 0 To i_oRow.Items.Count - 1 oGridCol = i_oRow.Items(I).Column 'deriving column object from row cell oGridCol.Width = Unit.Pixel(CalculateWidthHere()) 'setting calculated width Next End Sub
This works pretty well – that is until summary width of all columns combined hit’s 32K. If this happens – grid crashes: