CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: CEdit

  1. #1
    Join Date
    Aug 1999
    Posts
    171

    CEdit

    I have a CViewForm with some read-only CEdit controls of which their dollar values are initiated from calls to the doc. What is the easiest way to format the controls to show commas, i.e., the value 5555.45 is loaded into the control . . what it to appear as 5,555.45. Thanks for any suggestions.


  2. #2
    Join Date
    Jul 1999
    Location
    Moscow, Russia
    Posts
    667

    Re: CEdit

    Hi,
    Create handler for EN_UPDATE class like this:

    CString strText;
    CString strNewText;
    m_Edit.GetWindowText(strText);

    int nTextLength=strText.GetLength();
    int nPoint=strText.Find('.');
    int nCommas=nPoint/3;
    int nFirstComma=nPoint%3;

    if(nPoint==-1)
    {

    nCommas=nTextLength/3;
    nFirstComma=nTextLength%3;
    }
    else
    {
    nCommas=nPoint/3;
    nFirstComma=nPoint%3;
    }

    if(!nFirstComma)
    {
    --nCommas;
    nFirstComma=3;
    }
    CString strTemp;
    strTemp=strText.Mid(0,nFirstComma);
    strNewText=strTemp+',';
    for(int i=0;i<nCommas-1;i++)
    {
    strTemp=strText.Mid(nFirstComma+i*3-1,3);
    strNewText=strTemp+',';
    }

    strNewText=strNewText+strText.Right(nTextLength-nPoint);

    m_Edit.SetWindowText(strNewText);





    Hope this helps,
    Oleg.


  3. #3
    Join Date
    Aug 1999
    Posts
    171

    Re: CEdit

    Oleg, EXCELLENT! Thank you very much for your excellent solution to my problem.


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

Featured