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

    DDV control for minimum number of characters.

    Hello friends,

    Is there a way to easily set up a DDV function to check
    for a user input in an edit(or combo) box in a dialog box?

    It seems that there only exists a DDV that limits the max number of chars,
    but I can not find anything that checks for an input.

    Thanks,
    Dan B.


  2. #2
    Join Date
    May 1999
    Location
    WA
    Posts
    65

    Re: DDV control for minimum number of characters.

    You can just create a custom DDV function as follows:

    In the DoDataExchange function, add the following code OUTSIDE the blocks (As shown below):

    //{{AFX_DATA_MAP(CMyClassName)
    //}}AFX_DATA_MAP

    // Custom DDV Function (REPLACE IDC_YOUR_CONTROL_ID with your control's ID)
    // the "5" here is how many characters your control must have to qualify as
    // valid.
    DDV_MinimumChars(pDX, IDC_YOUR_CONTROL_ID, 5);




    Then, in your header file create a function prototype like the following:

    void DDV_MinimumChars(CDataExchange* pDX, UINT nID, int nMinChars);



    And in the main source (.cpp) file add the following code:

    void CYourClassName:DV_MinimumChars(CDataExchange* pDX, UINT nID, int nMinChars)
    {

    // The following IF statement makes sure that this function only runs when
    // your data is being saved.

    if( pDX->m_bSaveAndValidate )
    {
    CString sTemp = _T("");
    GetDlgItem(nID)->GetWindowText(sTemp);

    if( sTemp.GetLength() < nMinChars )
    {
    // The string listed in the control fails here.

    MessageBox( _T("You didn't enter enough characters!"), _T("Validation Error"), MB_OK|MB_ICONEXCLAMATION );

    pDX->PrepareEditCtrl(nID);
    pDX->Fail();
    }
    }
    }



    Good luck, hope this helps..

    - Troy

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