Recently I got a new windows mobile 6 Pocket PC phone. The datagrid provided in the Compact Framework is a very limited version of the Windows Forms DataGrid. Here is an example which will format the output of a datagrid. The windows forms datagrid has a GetColumnAtRow which you can override to return the formatted data. In the compact framework version you need to override the paint method to draw the formatted data in the datagrid. Note use the columns PropertyDescriptor's GetValue method to get the cells value. For this example I created a new column which converts true false to yes no.
Imports System.Data
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DataGrid1.DataSource = CreateTables()
Dim ts As New DataGridTableStyle
ts.MappingName = "Persons"
Dim textCol As New DataGridTextBoxColumn
textCol.MappingName = "Name"
textCol.HeaderText = "Name"
textCol.Width = 100
ts.GridColumnStyles.Add(textCol)
Dim boolCol As New YesNoColumn
boolCol.MappingName = "USA"
boolCol.HeaderText = "USA"
boolCol.Width = 30
ts.GridColumnStyles.Add(boolCol)
DirectCast(DataGrid1.DataSource, _
DataTable).DefaultView.AllowNew = False
DataGrid1.TableStyles.Add(ts)
End Sub
Private Function CreateTables() As DataTable
Dim dtVBReg As New DataTable("Persons")
dtVBReg.Columns.Add("Name")
dtVBReg.Columns.Add("USA", GetType(System.Boolean))
dtVBReg.LoadDataRow(New Object() {"Ken Tucker", True}, True)
dtVBReg.LoadDataRow(New Object() {"Cor Ligthert", False}, True)
Return dtVBReg
End Function
End Class
Public Class YesNoColumn
Inherits DataGridTextBoxColumn
Protected Overrides Sub Paint(ByVal g As System.Drawing.Graphics, ByVal bounds As System.Drawing.Rectangle, ByVal source As System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer, ByVal backBrush As System.Drawing.Brush, ByVal foreBrush As System.Drawing.Brush, ByVal alignToRight As Boolean)
'clear the cell
g.FillRectangle(backBrush, bounds)
Dim s As String
' Get the cells value
s = Me.PropertyDescriptor.GetValue(source.List(rowNum)).ToString
If s.ToLower = "true" Then s = "Yes" Else s = "No"
Dim r As Rectangle = bounds
r.Inflate(0, -1)
g.DrawString(s, New Font("Arial", 8, FontStyle.Regular), foreBrush, r)
End Sub
End Class