473,395 Members | 1,668 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Yes/No format string in datagrid?

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
1 2371
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tamlin | last post by:
Hi all, I'm getting a bug with the datagrid object. I've created one from scratch, bound it to a dataview with 2 int32 columns and formatted the output as currency. I've found that when you...
7
by: Eddy Soeparmin | last post by:
Hi, I need to display a DateTime field in 'mm/dd/yyyy' in a DataGrid.. On myGrid1 - Properties - Columns - myColumn1 - Text format string: I tried to put 'mm/dd/yyyy' in there and it displays...
10
by: ruca | last post by:
Hi I want to format some columns of my DataGrid control. Example, one of my fields of DataSet is a DATE field and in BD he is Ok, but when I show him in datagrid he comes with hours too. I...
6
by: Hutty | last post by:
I've looked around and have yet to find anything that would answer my question regarding formating a column in a datagrid. My grid looks like this as far as data" AMHQCON|51300.01|-3147 The...
4
by: yer darn tootin | last post by:
Does anyone know the sort expression for a column that's data has been returned in the format, eg '07 Jul 05'?? The sort expression {..:"dd mmm yy"} doesn't work ( if the column was returned as...
1
by: Julius Fenata | last post by:
Dear all, I need help to change my item-template value format... Here is my case, I have a datagrid, with 'SubjectPrice' field, and when the grid displayed, my 'SubjectPrice' field displayed...
5
by: Robin Tucker | last post by:
My database has a column for numeric data items. How can I use this number in the "format" command, such that for, say precision 2, I get numbers like 2011.01 or 2387.00 and for 4 I would get...
2
by: Derek Vincent | last post by:
What must I do to overcome a problem with my dates becoming formatted as "2/22/2525 12:00:00 AM" in the datagrid? I want to handle all dates as short string of format "2/22/2525." Otherwise when I...
2
by: Joel | last post by:
I'm trying to format the data from our database query that is being binded to a DataGrid. Basically an easy example to understand the problem is a field in the database uses 1's and 0's to show...
1
by: differentsri | last post by:
THIS IS AN ASP.NET 1.1 APPLICATION IAM TRYING TO UPDATE THE FIELD BUT I AM NOT ABLE TO UPDATE IT? CAN U TELL THE REASON ? IT IS GIVING THE FOLLOWING ERROR BELOW I HAVE ALSO GIVEN THE CODE OF...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.