Torna al Thread
Private Sub AggiungiColonne()
'il datatable contiene il nomeCampo e la descrizione
Dim i As Integer
For i = 0 To DT.Rows.Count - 1
Me.DG_Lista.Columns.Add(AddBoundColumn(DT.Rows(i)("DEscrizione"), DT.Columns("campo")))
Me.DG_Lista.Columns(i).HeaderStyle.Width = Unit.Pixel(100)
Next
End Sub
Private Function AddBoundColumn(ByVal Etichetta As String, ByVal DataField_O As DataColumn) As Object
Dim C_new As New BoundColumn
C_new.HeaderText = Etichetta
C_new.DataField = DataField_O.ColumnName ' Campo
C_new.Visible = True
'FORMATTO IL VALORE IN BASE AL TIPO
Select Case True
Case DataField_O.DataType Is GetType(System.DateTime)
C_new.DataFormatString = "{0:d}"
Case DataField_O.DataType Is GetType(System.String)
C_new.DataFormatString = "{0}"
End Select
AddBoundColumn = C_new
End Function