Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data Grid Property Builder

Status
Not open for further replies.

Dross

Programmer
Aug 16, 2001
212
US
Is there a way to format a phone number that is coming from a stored procedure to the datagrid in the Property Builder Data Formatting Expression box?

In other words, the phone number is coming from the stored procedure as 7575551212 and I want (757) 555-1212. I thought it could be done with a Data Formatting Expression, but I can't find one that works.
 
I haven't found any besides dates and numbers. This does work, however with a label:


Dim d As Double
d = 5555551212
Dim s As String
s = Format(d, "(000)000-0000")
Label2.Text = s


If you receive the value as a double, and cast it to a string with a format, you should be able to update the value in the grid cell with the string.

I do think the ideal way would be to format it on the database server. Is this sql server?

If it was SQL Server, you could make a user defined function. This is using a literal where you could replace it with a field name.


SELECT
'(' + LEFT(CONVERT(CHAR(10), 9165551212 ),3) + ')' +
RIGHT(LEFT(CONVERT(CHAR(10), 9165551212 ),6),3) + '-' +
RIGHT(CONVERT(CHAR(10), 9165551212 ),4)
FROM YourTable
 
Has anyone had any luck with this? I'm trying to det up the format in a cell in my datagrid & am having problems. So far I have used the DataGridTableStyle to set up the other formatting that I want (ie. Width, back color)Now I need to set one column to a format of (###)###-#### and having a problem.

What I have so far:
Dim ts1 As New DataGridTableStyle()
ts1.MappingName = "ztblPhoneExt"

' Add a GridColumnStyle and set its MappingName
' to the name of a DataColumn in the DataTable.
' Set the HeaderText and Width properties.

'' Add a first column style.
Dim LastNameCol As New DataGridTextBoxColumn()
LastNameCol.MappingName = "LastName"
LastNameCol.HeaderText = "Last Name"
LastNameCol.Width = 180
ts1.GridColumnStyles.Add(LastNameCol)

'' Add a second column style.
Dim FirstNameCol As New DataGridTextBoxColumn()
FirstNameCol.MappingName = "FirstName"
FirstNameCol.HeaderText = "First Name"
FirstNameCol.Width = 180
ts1.GridColumnStyles.Add(FirstNameCol)

'' Add a third column style.
Dim PhoneNum As New DataGridTextBoxColumn()
PhoneNum.MappingName = "PhoneNum"
PhoneNum.HeaderText = "Phone Number"
PhoneNum.Width = 110

ts1.GridColumnStyles.Add(PhoneNum)

My problem is with the third column. I would like the data to be formatted as a phone number when the grid is populated. The data shows as 5553331212 in the table (SQL)Any suggestions?

Thanks,
Corinne
 

why don't you format it in the select query you are using in your stored procedure. I implimented something similar to it. The only difference was there was no stored procedure and it was an access database. my database stores phone# like 881114063 and i am displaying it like (08) 81114063. Check this out, it might help you!!!

selectString = "SELECT ProspectID, Surname, Initials, StreetNo, " & _
"StreetAddress, Suburb, State, " & _
"FORMAT(PostCode," & """ 0000""" & ")" & _
" AS PostCode, " & _
"FORMAT(Phone," & """(00) 00000000""" & ")" & _
" AS Phone, PrintDate FROM Prospects " & _
"WHERE MID(Phone,2) = " & txtPhone.Text & _
" AND Status IS NULL ORDER BY Surname"

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top