RE:dar formato a un datagrid
espero te sirva
grid_clientes.TableStyles.Add(FormatoGrid(grid_clientes, DataSetclientes.Tables(0))) ' Se da formato al grid
grid_clientes.Width = total + 55
Public Function FormatoGrid(ByRef Grid As DataGrid, ByRef ds As DataTable) As DataGridTableStyle
Dim tablestyle As New DataGridTableStyle
Dim dtcolumna As DataGridTextBoxColumn
Dim columna As DataColumn
Dim gr As Graphics
Dim i, j, ancho, maximo As Integer
gr = Grid.CreateGraphics
Grid.TableStyles.Clear()
tablestyle = New DataGridTableStyle
tablestyle.MappingName = ds.TableName
tablestyle.AlternatingBackColor = Color.GhostWhite
tablestyle.ForeColor = Color.MidnightBlue
tablestyle.GridLineColor = System.Drawing.Color.RoyalBlue
tablestyle.HeaderBackColor = Color.MidnightBlue
tablestyle.HeaderForeColor = Color.Lavender
tablestyle.LinkColor = Color.Teal
tablestyle.SelectionBackColor = Color.DarkSeaGreen
tablestyle.SelectionForeColor = Color.Black
tablestyle.PreferredRowHeight = 20
total = 0
Try
For i = 0 To ds.Columns.Count - 1
columna = ds.Columns(i)
maximo = 0
ancho = gr.MeasureString(ds.Columns(i).ColumnName, Grid.Font).Width + 1
For j = 0 To ds.Rows.Count - 1
If Not IsDBNull(ds.Rows(j)(i)) Then
maximo = gr.MeasureString(CStr(ds.Rows(j)(i)), Grid.Font).Width + 1
End If
If (maximo > ancho) Then
ancho = maximo
End If
Next
dtcolumna = New DataGridTextBoxColumn
dtcolumna.TextBox.Enabled = True
dtcolumna.HeaderText = columna.ColumnName
dtcolumna.MappingName = columna.ColumnName
dtcolumna.Width = ancho
If columna.DataType Is System.Type.GetType("System.Int16") Or columna.DataType Is System.Type.GetType("System.Int32") Or columna.DataType Is System.Type.GetType("System.Single") Then
dtcolumna.Alignment = HorizontalAlignment.Right
End If
tablestyle.GridColumnStyles.Add(dtcolumna)
total = total + ancho
Next
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Function
End Try
FormatoGrid = tablestyle
End Function