• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 445
  • Last Modified:

check box to edit box

Hi expert

I have a MFC check box on other dialog form. I have two check box which is user can choose either check box # 1 or check box # 2.

How?
1. If I want showing the user selection (let say check box #2) in edit box. This edit box located on other dialog form.
0
khairulzams
Asked:
khairulzams
2 Solutions
 
DanRollinsCommented:
If only one of the items should be checked, then you should use a pair of readio buttons instead.  Check out the article:

    Radio Buttons in MFC Dialogs
    http://www.experts-exchange.com/A_1518.html 
As to accessing the checked or not-checked setting in one dialog from another dialog...
Your dialog should have a member variable that echos the state of the checkbox (or radio button).  All you need to do is access that member variable from the other dialog program code.  Your question is rather unclear, otherwise, I'd provide some example code.
0
 
umamaheswari_KCommented:
Do the following for check box # 1 or check box # 2.
void CMyDlg::Onchk1()
{
      CButton *pButton=(CButton*)GetDlgItem(IDC_CHK1);
      int nState=pButton->GetCheck();
      if(nState==1)
      {
            UpdateData(TRUE);
                CEditDlg *dlg;
                dlg->SetDlgItemText(IDC_EDT,"Checkbox1 Selected");
      }
}
0
 
AndyAinscowCommented:
I agree with Dan about the usage of radio buttons if it is only to be one check box being checked and one of them must be checked.

To update the other dialog box when one is checked the code by umamaheswari_K will help.  Note that it is not complete and in one point misleading.

Using that code snippet.
The CMyDlg needs to have a member variable (public) declared in the header which is a ponter to the dialog containing the edit box.
ie. CEditDlg* dlg should be in the header file, not the function.  The value should be set to NULL in the constructor.

void CMyDlg::Onchk1()
{
      CButton *pButton=(CButton*)GetDlgItem(IDC_CHK1);
      int nState=pButton->GetCheck();
      if(nState==1)
      {
            if(dlg != NULL)
              dlg->SetDlgItemText(IDC_EDT,"Checkbox1 Selected");
      }
}

If you did use radio buttons then the code is basically the same.  Just have an event handler for the click event of the button (check or radio).
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
khairulzamsAuthor Commented:
umamaheswari_K:

I try to follow your code example. No problem during build and execute the code.  

But the problem occurred during the process. When I click the check box , then the error appeared

"Run-Tome Check Failure #3 = The variable "dlg" is being used without being initialized"

What that mean

Thank and Regard
0
 
AndyAinscowCommented:
see my comment for an explanation and how to correct it.
0
 
khairulzamsAuthor Commented:
Hi Andy...

change the code into your solution ..no problem during building process..but the problem occurred when I check the check box..

"Unhandled exception at 0x58ad508c (mfc90d.dll) in ReTIME.exe: 0xC0000005: Access violation reading location 0xccccccec."

I will check back again..maybe I missed someting

Thank and Regard
0
 
AndyAinscowCommented:
You have set the pointer to the edit dialog box have you not?
Also check the ID's of the edit and check boxs, are they the correct values ?
0
 
khairulzamsAuthor Commented:
Hi Andy ...

Here my situation
My Check box located in CMyOptionDlg
                  IDC_CHECK_OPTION1 = m_CheckOption1 (int)
                  IDC_CHECK_OPTION2 = m_CheckOption2 (int)
My Edit Box (will displayed selected check box) located in CMyDlg
                  IDC_EDIT_CHECKSELECT   = m_SelectCheck (CString)


1. I put CMyDlg *dlg in header file
2. set dlg = NULL in constructor
3. here my implemet code

void CMyOptionDlg::OnBnClicked()
{
      // TODO: Add your control notification handler code here
      UpdateData(TRUE);
      CButton *pButton=(CButton*)GetDlgItem(IDC_CHECK_OPTION1);
      int nState = pButton->GetCheck();
      if (nState == 1)
      {
            //UpdateData (TRUE);
            //CSingleRTSView *dlg;
            if (dlg != NULL);
                  dlg->SetDlgItemText(IDC_EDIT_CHECKSELECT, "Option 1");
      }

}

Where the error?.

Thank and Regard
0
 
AndyAinscowCommented:
Repeat - Have you set the pointer dlg to the edit dialog?

eg. somewhere you should have code that works like this

void CSingleRTSView::ShowOptions()
{
  CMyOptionDlg dlgOptions;
  dlgOptions.dlg = this;
  dlgOptions.DoModal();
}
0
 
khairulzamsAuthor Commented:
ok andy...it done..problem fixed...got an error in setting the pointer..

thank guys
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now