Hi,
Create a class that inherits from datagridtextboxcolumn to do that.
Add the class to the grids tablestyle. Here is an example that displays yes
or no
Dim ds As New DataSet
Dim phasetable As DataTable
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim conn As SqlConnection
Dim strConn As String
Dim strSQL As String
Dim da As SqlDataAdapter
'strConn = "Provider = Microsoft.Jet.OLEDB.4.0;"
'strConn &= "Data Source = Northwind.mdb;"
strConn = "Server = (local);"
strConn &= "Database = NorthWind;"
strConn &= "Integrated Security = SSPI;"
conn = New SqlConnection(strConn)
da = New SqlDataAdapter("Select * From Products", conn)
da.Fill(ds, "Products")
Dim ts As New DataGridTableStyle
ts.MappingName = ds.Tables("Products").TableName
Dim colDiscontinued As New YesNoColumn
With colDiscontinued
..MappingName = "Discontinued"
..HeaderText = "Discontinued"
..Width = 80
End With
Dim colName As New DataGridTextBoxColumn
With colName
..MappingName = "ProductName"
..HeaderText = "Product Name"
..Width = 180
End With
ts.GridColumnStyles.Add(colName)
ts.GridColumnStyles.Add(colDiscontinued)
DataGrid1.TableStyles.Add(ts)
phasetable = ds.Tables("Products")
DataGrid1.DataSource = phasetable
ts = Nothing
colDiscontinued = Nothing
colName = Nothing
End Sub
The datagrid column
Public Class YesNoColumn
Inherits DataGridTextBoxColumn
Public Sub New()
Me.ReadOnly = True
End Sub
Protected Overrides Function GetColumnValueAtRow(ByVal source As
System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer) As Object
Dim b As Boolean = False
Try
b = CType(MyBase.GetColumnValueAtRow(source, rowNum), Boolean)
Catch ex As Exception
End Try
If b = True Then
Return "Yes"
Else
Return "No"
End If
End Function
End Class
Ken
--------------------------
"Agnes" <ag***@dynamictech.com.hk> wrote in message
news:eU**************@TK2MSFTNGP09.phx.gbl...
I got a true or false column in my Datagrid, The datafield is "bit" in the
sql tables,
However, I want to display "A" if the field is true, "B" is false .
Is this possible to do ?? or I should add one more field in my tables and
put "A"or "B" in it ? thanks