Results 1 to 13 of 13

Thread: formatting phone in datagridview

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2006
    Posts
    176

    formatting phone in datagridview

    Hi All.
    I would like to format PHONE column on DGV. For instance 1234567891 need to format like (123)456-7891. If is it possible how to do?
    Thanks.
    Last edited by eugz; Apr 25th, 2008 at 02:52 PM.

  2. #2
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: formatting phone in datagridview

    see this thread for formatting ph#

    http://www.vbforums.com/showthread.php?t=519707
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2006
    Posts
    176

    Re: formatting phone in datagridview

    dbasnett, thanks for replay.
    If I understood link correct it is formatting for textbox and I try to formatting phone in datagridview. Any help will appraciate.
    Thanks.

  4. #4
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: formatting phone in datagridview

    post the code you are having problems with.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: formatting phone in datagridview

    Edit the DefaultCellStyle property of your column and in the CellStyle Builder dialogue set its Format property to the same format string as was suggested in the thread that dbasnett linked to.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Nov 2006
    Posts
    176

    Re: formatting phone in datagridview

    Hi All.
    I would like to format column PhoneHome in datagridview
    Code:
    Me.DataGridView.Columns("PhoneHome").DefaultCellStyle.Format = (String.Format("({0}) {1}-{2}", "PhoneHome".Substring(0, 3), "PhoneHome".Substring(3, 3), "PhoneHome".Substring(6)))
    But in DGV I got (Pho) neH-ome. What I did worng? Table hold PhoneHome as varchar(10).
    Thanks.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Nov 2006
    Posts
    176

    Re: formatting phone in datagridview

    Hi All.
    In DB PhoneHome bigint
    In DGV
    Code:
    Me.DataGridView.Columns("PhoneHome").DefaultCellStyle.Format = "(###) ###-####"
    It works.

    But when I leave that field empty on Detail form and click SAVE button I get error message:
    "Input string was not in a correct format.Couldn't store <> in PhoneHome Column. Expected type is Int64."

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: formatting phone in datagridview

    Does your column allow nulls? If not then you cannot leave it empty.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Nov 2006
    Posts
    176

    Re: formatting phone in datagridview

    Hi jmcilhinney
    In DB that column allow null.
    Thanks.

  10. #10

  11. #11
    PowerPoster Deepak Sakpal's Avatar
    Join Date
    Mar 2002
    Location
    Mumbai, India
    Posts
    2,424

    Re: formatting phone in datagridview

    "Input string was not in a correct format.Couldn't store <> in PhoneHome Column. Expected type is Int64."

    Data Type of the field in database is of numeric type and you are inserting text value, so that is obvious. Change the data type so that it can accept text values.

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Nov 2006
    Posts
    176

    Re: formatting phone in datagridview

    Hi Deepak Sakpal
    I did it. I changed data type bigint to varchar. But in this case
    Code:
    Me.DataGridView.Columns("PhoneHome").DefaultCellStyle.Format = "(###) ###-####"
    doesn't work.
    Thanks.

  13. #13

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width