473,395 Members | 1,443 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.

I guess nobody know formatting in the DataGridView?????????????????????

I have an unbound DataGrieView on a Windows form (VS 2005) and I have added
a column to a DataGridView

Dim textCol As New DataGridViewTextBoxColumn

textCol.Name = "ContactPhone1"

dgcontacts.Columns.Insert(.Columns.Count, textCol)

dgcontacts.Columns("ContactPhone1").DefaultCellSty le.Format = "(000)
000-0000"

When the grid is displayed on the form, there is no formatting in the cell.
What am I doing wrong and How can I fix it?

Thanks

Apr 4 '07 #1
2 3109
One way to do special mask type formatting is to subscribe to the
CellFormatting event and do it there.

Dim o As Object = e.Value
If Not (o Is Nothing) And e.ColumnIndex = 1 And
e.Value.ToString().Length = 10 Then
Dim s As String = o.ToString()
e.Value = String.Format("({0}){1}-{2}", s.Substring(0, 3),
s.Substring(3, 3), s.Substring(6))
e.FormattingApplied = True
End If

====================
Clay Burch
Syncfusion, Inc.

Apr 5 '07 #2
Hello Zim,
dgcontacts.Columns("ContactPhone1").DefaultCellSty le.Format = "(000)
000-0000"

When the grid is displayed on the form, there is no formatting in the
cell. What am I doing wrong and How can I fix it?
What is the type of the ContactPhone? The format string should work for a
number, but if this is a string, I think it will just display the string.

dim phone as string = "1234567890"
Console.WriteLine(String.Format(phone, "(000) 000-0000") 'outputs "1234567890"
Console.WriteLine(CInt(phone).ToString("000) 000-0000") 'outputs "(123)
456-7890"

Jim Wooley
http://devauthority.com/blogs/jwooley
Apr 8 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: jbehrne | last post by:
Hi all, I am using a datagridview in .Net 2005 to display data from a stored procedure using a System.Data.SQLClient connection. After the stored procedure dumps the data into a dataset and the...
16
by: silversurfer2025 | last post by:
Hello everyone, once again, I have a very basic problem in C++, which I was not able to solve (maybe because of my Java-Experience or just because it is always the small syntax-things which break...
2
by: ScottL | last post by:
Hi - I have an issue with the DataGridView. I am formatting the DGV in code and not using the designer. I drop a DGV on my form, code the formatting including some columns.visible = false. After...
7
by: Ryan | last post by:
I have a DataGridView which displays numeric (Int32) data from an underlying database. I want the numbers to be displayed in numeric format "#,###" (with commas). I want to also limit the user so...
3
by: Zim Babwe | last post by:
I posted the other day and so far no replies.... :-( I have a VB Windows Form (VS 2005) and on the form is a datagridview control. It was populated by: datagridview1.DataSource = tbl
2
by: =?Utf-8?B?Uml0YUc=?= | last post by:
Hello. I could not find a Web discussion group (only saw Web Services) so am posting my question here. I have a C# Web application that has a form with a datagrid. One of the columns of the data...
2
by: =?Utf-8?B?VG9jbw==?= | last post by:
Hello. My goal is to pain the entire row fore color as Red. If the value of column 24 is true (boolean), I wish to paint the row as Red. Otherwise, leave row as default (no formatting). The...
3
by: Cdude | last post by:
I am using this code at the moment to format the column this.itemsDataGrid.Columns.DefaultCellStyle.Format = "c"; but i get the error "Object reference not set to an instance of an object. "...
1
by: Ben456 | last post by:
Hello, I'm trying to figure out how to keep my cell formatting the same even after I've clicked a column sort header. Basically I've programmatically changed forecolors and backcolors 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.