By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,569 Members | 1,630 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,569 IT Pros & Developers. It's quick & easy.

Yes/No format string in datagrid?

P: n/a
I am displaying a boolean field in a grid & want to format it Yes/No. Can
someone tell me what the formatstring for this is? That is,

DataGridTextBoxColumn.Format = ??

Jeremy
Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi,

Create a class that inherits from datagridtextboxcolumn to do that.
Add the class to the grids tablestyle.

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

--------------------------

"Jeremy" <je****@ninprodata.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
I am displaying a boolean field in a grid & want to format it Yes/No. Can
someone tell me what the formatstring for this is? That is,

DataGridTextBoxColumn.Format = ??

Jeremy

Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.