Solved

IDC_STATIC Problem?

Posted on 2008-10-11
24
1,180 Views
Last Modified: 2013-11-20
Hallo all,
I have a problem with changing text for IDC_STATIC. I have 1 Combobox, 1 button and 1 idc_static text in my dialog. For initializing, everything worked quite well. Now after clicking the button, I want to update the new text for the idc_static and also for the combobox. It worked for the combobox but for the static text, it didn't work, and I don't know why. Can somebody help me?

Thank you very much

DDX_Text(pDX, IDC_STATIC_RPA_STATUS, m_strRPAStatus);	

DDX_Control(pDX, IDC_COMBO_STATE_REASON, m_StateReasonCtrl);
 

m_pParentWnd->GetRpaProps()->m_strRPAStatus = StringFromVar(pRpaTab->GetFieldValue("Status")); ---> it didn't work

// CString Status = StringFromVar(pRpaTab->GetFieldValue("Status"));

// SetDlgItemText(IDC_STATIC_RPA_STATUS, Status);              ---> this also didn't work

m_pParentWnd->GetRpaProps()->m_StateReasonCtrl.SetCurSel(nID); ---> it worked perfectly

Open in new window

0
Comment
Question by:rambovn
  • 12
  • 9
  • 3
24 Comments
 
LVL 19

Expert Comment

by:LordOfPorts
ID: 22695184
The following is one possible solution:

1. Declare m_strRPAStatus as a CStatic member variable:

CStatic m_strRPAStatus;

2. Use the following macro:

DDX_Control(pDX, IDC_STATIC_RPA_STATUS, m_strRPAStatus);

3. To update the text call the following line:

m_strRPAStatus.SetWindowText(_T("New text"));
0
 
LVL 8

Author Comment

by:rambovn
ID: 22695244
Hallo LordOfPorts,
Thank you for your quick reply, I will test it again, but I am still wondering, it worked at the 1st time opening the dialog, why didn't it work after clicking the button on this dialog?
Regards
0
 
LVL 19

Expert Comment

by:LordOfPorts
ID: 22695487
Actually it will work if you call UpdateData(FALSE); after changing the value of the CString variable.
m_pParentWnd->GetRpaProps()->m_strRPAStatus = StringFromVar(pRpaTab->GetFieldValue("Status"));

UpdateData(FALSE);

Open in new window

0
 
LVL 8

Author Comment

by:rambovn
ID: 22696605
Hi LordOfPorts,
I already tried UpdateData(False); and it didn't work :-(
I am still thinking about your 3 ways above, because if I change the type of the variable, I have to change my whole program, and it will take much time :-(
Do you have any other idea?
Thank you very much
Regards,
0
 
LVL 8

Author Comment

by:rambovn
ID: 22696629
Sorry you gave one solution but I thought there were 3 :-(
0
 
LVL 8

Author Comment

by:rambovn
ID: 22696701
I did exactly in the way in your 1st post, but there was Debug Assert Error at the 1st time opening the dialog :-(

ASSERT(::IsWindow(m_hWnd));
m_hWnd == NULL



0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 22697801
IDC_STATIC is a generic ID for static controls.  To do what you want you need to define a unique  ID for each static control you want to manipulate the text of.
0
 
LVL 19

Expert Comment

by:LordOfPorts
ID: 22698118
rambovn, you mentioned that with CString it had worked during the dialog initialization so you have already correctly set the ID of your CStatic control to IDC_STATIC_RPA_STATUS, correct?

I have tested the first solution with mapping to control to a CStatic member variable as well as using UpdateData(FALSE); when the member variable was of CString data type successfully so let's check the configuration one more time assuming you are using the CStatic member variable approach from the first post, i.e. how does the OnInitDialog() look like? It would be something like:
BOOL CYourDialogDerivedClassDlg::OnInitDialog()

{

	CDialog::OnInitDialog();
 

	// ...
 

	// TODO: Add extra initialization here

	m_strRPAStatus.SetWindowText(_T("Original Text"));

	

	return TRUE;

}

Open in new window

0
 
LVL 19

Expert Comment

by:LordOfPorts
ID: 22698142
...and just to also confirm, you have replaced the following line:

DDX_Text(pDX, IDC_STATIC_RPA_STATUS, m_strRPAStatus); // when mapping CString

with:

DDX_Control(pDX, IDC_STATIC_RPA_STATUS, m_strRPAStatus); // when mapping CStatic
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 22698147
>> It worked for the combobox but for the static text, it didn't work, and I don't know why

(Was the text set in the resource editor ?)


The question is not very clear about how the dialog controls are (ID, initial caption)
0
 
LVL 8

Author Comment

by:rambovn
ID: 22698320
To Andy: My ID is already unique, it already worked for the initialization. It didn't work only when I clicked the button on the same dialog.
Can you explain your question "Was the text set in the resource editor" more clearly? Thank you very much
To LordOfPorts: I already did like the way you wrote, but it didn't work also for the inialization so I changed it back
I attached my code again






CRPAProperties::CRPAProperties(CWnd* pParent /*=NULL*/)

	: CDialog(CRPAProperties::IDD, pParent),

	m_pParentWnd (pParent)

{

	//{{AFX_DATA_INIT(CRPAProperties)

	m_strRPAStatus = _T("");

	//}}AFX_DATA_INIT

	m_pParentWnd  = pParent;

}
 

void CRPAProperties::DoDataExchange(CDataExchange* pDX)

{

	CDialog::DoDataExchange(pDX);

	//{{AFX_DATA_MAP(CRPAProperties)

	DDX_Text(pDX, IDC_STATIC_RPA_STATUS, m_strRPAStatus);

	DDX_Control(pDX, IDC_COMBO_STATE_REASON, m_StateReasonCtrl);

//	DDX_Control(pDX, IDC_STATIC_RPA_STATUS, m_strRPAStatus);

	//}}AFX_DATA_MAP

}
 

BEGIN_MESSAGE_MAP(CRPAProperties, CDialog)

	ON_BN_CLICKED(IDC_BUTTON_REFUSE_RPA_ON_PROPERTYDLG, OnButtonRefuseRPA)

END_MESSAGE_MAP()
 

BOOL CRPAProperties::OnInitDialog()

{

	CDialog::OnInitDialog();

	PopulateStateReasonCombo();

	return true;

}
 

// Opening the dialog

void GPSView_Fen::OnRPAProperty()

{

	m_pRPAPropsDlg = new CRPAProperties(this);

	

	CVectorBlock* bsel;

	CListElements* sel = m_pGeoWinManager->GetSelectedVectors( &bsel );

CVectorBasis* el = (CVectorBasis*)sel->obj;

	

	// get the dataset

	long linkid = el->ID();

	m_pRPAPropsDlg->m_pRPATab->GetRecordByID(linkid);

	m_pRPAPropsDlg->m_strIdOrder = StringFromVar(m_pRPAPropsDlg->m_pRPATab->GetFieldValue("ID"));

	m_pRPAPropsDlg->m_strRPAStatus = StringFromVar(m_pRPAPropsDlg->m_pRPATab->GetFieldValue("Status"));

// 	CString	Status1 = StringFromVar(m_pRPAPropsDlg->m_pRPATab->GetFieldValue("Status"));

// 	m_pRPAPropsDlg->m_strRPAStatus.SetWindowText(Status1);

	m_pRPAPropsDlg->m_strRemark = StringFromVar(m_pRPAPropsDlg->m_pRPATab->GetFieldValue("Bemerkung"));	

	m_pRPAPropsDlg->m_strCreateTime = StringFromVar(m_pRPAPropsDlg->m_pRPATab->GetFieldValue("Time"));	

	

	CString filter;

	filter.Format("ID_ORDER = %d", linkid);

	if (m_pRPAPropsDlg->m_pLinkTable->SetFilter(filter))

	{

		variant_t IDFBLE;

		IDFBLE = m_pRPAPropsDlg->m_pLinkTable->GetFieldValue("IDFBAKTI");

		// get FBID for field block

		if ((long)IDFBLE != 0)

		{

			m_pRPAPropsDlg->isFB = true;

			dsActi->m_tab->GetRecordByID(IDFBLE);

			m_pRPAPropsDlg->m_strFLIKFLEK = StringFromVar(dsActi->m_tab->GetFieldValue("FBID"));

		}		

		else if ((long)(IDFBLE = m_pRPAPropsDlg->m_pLinkTable->GetFieldValue("IDLEAKTI")) != 0)// get FLEK for LE

		{

			m_pRPAPropsDlg->isLE = true;

			IDFBLE = m_pRPAPropsDlg->m_pLinkTable->GetFieldValue("IDLEAKTI"); 

			dsActiLE->m_tab->GetRecordByID(IDFBLE);

			m_pRPAPropsDlg->m_strFLIKFLEK = StringFromVar(dsActiLE->m_tab->GetFieldValue("FLEK"));

		}

		

	}

	m_pRPAPropsDlg->m_pLinkTable->SetFilter(""); // reset the filter on the link table

	if (m_pRPAPropsDlg->DoModal () == IDOK) {

		SendMessage(GeoFenster::REFRESH_RPA_LIST_MSG);

		RefreshTableSelection(0,0);

	}

	if (m_pRPAPropsDlg)

		delete m_pRPAPropsDlg;

}

Open in new window

0
 
LVL 19

Expert Comment

by:LordOfPorts
ID: 22698378
Ok, so m_strRPAStatus is a member variable of the CRPAProperties class and OnRPAProperty is a member method of the GPSView_Fen. Try calling UpdateData(FALSE); from GPSView_Fen::OnRPAProperty() in the following manner:
m_pRPAPropsDlg->m_strRPAStatus = StringFromVar(m_pRPAPropsDlg->m_pRPATab->GetFieldValue("Status"));

m_pRPAPropsDlg->UpdateData(FALSE);

Open in new window

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 8

Author Comment

by:rambovn
ID: 22698386
sorry I sent it before I finished :-(
It worked quite well until I go to the function: void CRejectRpaReason::OnOK()
But what made me confused is why I can update for the combobox, but not for the static :-(


CRPAProperties::CRPAProperties(CWnd* pParent /*=NULL*/)

        : CDialog(CRPAProperties::IDD, pParent),

        m_pParentWnd (pParent)

{

        //{{AFX_DATA_INIT(CRPAProperties)

        m_strRPAStatus = _T("");

        //}}AFX_DATA_INIT

        m_pParentWnd  = pParent;

}

 

void CRPAProperties::DoDataExchange(CDataExchange* pDX)

{

        CDialog::DoDataExchange(pDX);

        //{{AFX_DATA_MAP(CRPAProperties)

        DDX_Text(pDX, IDC_STATIC_RPA_STATUS, m_strRPAStatus);

        DDX_Control(pDX, IDC_COMBO_STATE_REASON, m_StateReasonCtrl);

//      DDX_Control(pDX, IDC_STATIC_RPA_STATUS, m_strRPAStatus);

        //}}AFX_DATA_MAP

}

 

BEGIN_MESSAGE_MAP(CRPAProperties, CDialog)

        ON_BN_CLICKED(IDC_BUTTON_REFUSE_RPA_ON_PROPERTYDLG, OnButtonRefuseRPA)

END_MESSAGE_MAP()

 

BOOL CRPAProperties::OnInitDialog()

{

        CDialog::OnInitDialog();

        PopulateStateReasonCombo();

        return true;

}
 

CRPAProperties* GetRpaProps() {return m_pRPAPropsDlg;}
 

CRPAProperties *m_pRPAPropsDlg;
 

GPSView_Fen::GPSView_Fen() : SelState(GetUserProps())	

{	

	m_pRPAPropsDlg = NULL;

}
 

// Opening the dialog with full information of one Fieldblock

void GPSView_Fen::OnRPAProperty()

{

        m_pRPAPropsDlg = new CRPAProperties(this);

        

        CVectorBlock* bsel;

        CListElements* sel = m_pGeoWinManager->GetSelectedVectors( &bsel );

        CVectorBasis* el = (CVectorBasis*)sel->obj;

        

        // get the dataset

	long linkid = el->ID();

	m_pRPAPropsDlg->m_pRPATab->GetRecordByID(linkid)

        m_pRPAPropsDlg->m_strRPAStatus=   StringFromVar(m_pRPAPropsDlg->m_pRPATab->GetFieldValue("Status"));
 

        if (m_pRPAPropsDlg->DoModal () == IDOK) {

              

        }

        if (m_pRPAPropsDlg)

                delete m_pRPAPropsDlg;

}
 

// After choosing the reason for rejecting RPA, the dialog will be updated with RPA's new status

void CRejectRpaReason::OnOK() 

{

	UpdateData(TRUE);
 

	CComboBox* pCombo = (CComboBox*)GetDlgItem( IDC_COMBO_RPA_REFUSE_REASON );	

	// 	

	CString TaskCodeText; 

	int selectedIndex = pCombo->GetCurSel();

	if (selectedIndex == -1)

	{	

		AfxMessageBox("Bitte geben Sie den Grund der Abweisung an!");

		return;

	}

	else

	{		

		CString stateReasonText;

		DBTable* pRpaTab = m_pParentWnd->GetRPAWebServiceDataset()->m_tab;

		DBTable* pStateReasonTab =  m_pParentWnd->GetRPAWebServiceDataset()->GetStateReasonTable();

		pCombo->GetLBText(selectedIndex, stateReasonText);

		pStateReasonTab->SetFilter("Name = '" + stateReasonText + "'");

		long nID = LongFromVar(pStateReasonTab->GetFieldValue("ID"));
 

		pRpaTab->SetFieldValue("State Reason", (_variant_t)(long)nID);

		

		pRpaTab->SetFieldValue("Status", (_variant_t)("Abgearbeitet"));

		pStateReasonTab->SetFilter("");

		if (m_pParentWnd->GetRpaProps())

		{

		 	m_pParentWnd->GetRpaProps()->m_strRPAStatus = StringFromVar(pRpaTab->GetFieldValue("Status"));
 

		//	m_pParentWnd->GetRpaProps()->m_strRPAStatus.SetWindowText(StringFromVar(pRpaTab->GetFieldValue("Status")))  ;

			

//   			CString Status = StringFromVar(pRpaTab->GetFieldValue("Status"));

// 		 	SetDlgItemText(IDC_STATIC_RPA_STATUS, Status);

		

			//m_pParentWnd->GetRpaProps()->m_strRPAStatus.SetWindowText(Status);

 			m_pParentWnd->GetRpaProps()->m_StateReasonCtrl.SetCurSel(nID);

			m_pParentWnd->GetRpaProps()->Invalidate();

			UpdateData(FALSE);

		}		

		

	}	

	CDialog::OnOK();

}

Open in new window

0
 
LVL 19

Expert Comment

by:LordOfPorts
ID: 22698422
You need to call the UpdateData method of the window to which m_strRPAStatus belongs because it is mapped to a CString variable. With the combo box you are calling m_pParentWnd->GetRpaProps()->Invalidate(); which takes care of this for you.
0
 
LVL 8

Author Comment

by:rambovn
ID: 22698426
I already tried Updatedata (false); in OnRpaProperty() but it didn't work :-(
0
 
LVL 8

Author Comment

by:rambovn
ID: 22698446
Thank you very much for your patience.
I just added this line this afternoon for trying to solve my Static text problem, without this line, it also worked well for the combo box.
m_pParentWnd->GetRpaProps()->Invalidate();


0
 
LVL 19

Expert Comment

by:LordOfPorts
ID: 22698450
Can you post the syntax regarding how you called UpdateData(FALSE); in the OnRpaProperty()?

m_pRPAPropsDlg->UpdateData(FALSE); // ?
0
 
LVL 8

Author Comment

by:rambovn
ID: 22698471
void GPSView_Fen::OnRPAProperty()
{
        m_pRPAPropsDlg = new CRPAProperties(this);
       
        CVectorBlock* bsel;
        CListElements* sel = m_pGeoWinManager->GetSelectedVectors( &bsel );
        CVectorBasis* el = (CVectorBasis*)sel->obj;
       
        // get the dataset
        long linkid = el->ID();
        m_pRPAPropsDlg->m_pRPATab->GetRecordByID(linkid)
        m_pRPAPropsDlg->m_strRPAStatus=   StringFromVar(m_pRPAPropsDlg->m_pRPATab->GetFieldValue("Status"));
 
      m_pRPAPropsDlg->UpdateData(FALSE);
        if (m_pRPAPropsDlg->DoModal () == IDOK) {
             m_pRPAPropsDlg->UpdateData(FALSE);
        }
       m_pRPAPropsDlg->UpdateData(FALSE);
        if (m_pRPAPropsDlg)
                delete m_pRPAPropsDlg;
}
I already tried it at 3 places like above

0
 
LVL 19

Expert Comment

by:LordOfPorts
ID: 22698616
Can you display the value of the m_strRPAStatus variable after setting it, i.e. in the code above:

m_pRPAPropsDlg->m_strRPAStatus = StringFromVar(m_pRPAPropsDlg->m_pRPATab->GetFieldValue("Status"));
AfxMessageBox(m_pRPAPropsDlg->m_strRPAStatus);

Is it the correct new value?
0
 
LVL 8

Author Comment

by:rambovn
ID: 22698631
yes it is correct :-(, my problem was so strange for me :-(
OnRPAProperty worked perfectly until now, the problem comes from this function (see the line that is bold), and I already checked the value of " m_pParentWnd->GetRpaProps()->m_strRPAStatus", it is also correct, but why didn't it appear on the dialog?

void CRejectRpaReason::OnOK()
{
        UpdateData(TRUE);
 
        CComboBox* pCombo = (CComboBox*)GetDlgItem( IDC_COMBO_RPA_REFUSE_REASON );      
        //      
        CString TaskCodeText;
        int selectedIndex = pCombo->GetCurSel();
        if (selectedIndex == -1)
        {      
                AfxMessageBox("Bitte geben Sie den Grund der Abweisung an!");
                return;
        }
        else
        {              
                CString stateReasonText;
                DBTable* pRpaTab = m_pParentWnd->GetRPAWebServiceDataset()->m_tab;
                DBTable* pStateReasonTab =  m_pParentWnd->GetRPAWebServiceDataset()->GetStateReasonTable();
                pCombo->GetLBText(selectedIndex, stateReasonText);
                pStateReasonTab->SetFilter("Name = '" + stateReasonText + "'");
                long nID = LongFromVar(pStateReasonTab->GetFieldValue("ID"));
 
                pRpaTab->SetFieldValue("State Reason", (_variant_t)(long)nID);
               
                pRpaTab->SetFieldValue("Status", (_variant_t)("Abgearbeitet"));
                pStateReasonTab->SetFilter("");
                if (m_pParentWnd->GetRpaProps())
                {
                        m_pParentWnd->GetRpaProps()->m_strRPAStatus = StringFromVar(pRpaTab->GetFieldValue("Status"));
 
                //      m_pParentWnd->GetRpaProps()->m_strRPAStatus.SetWindowText(StringFromVar(pRpaTab->GetFieldValue("Status")))  ;
                       
//                      CString Status = StringFromVar(pRpaTab->GetFieldValue("Status"));
//                      SetDlgItemText(IDC_STATIC_RPA_STATUS, Status);
               
                        //m_pParentWnd->GetRpaProps()->m_strRPAStatus.SetWindowText(Status);
                        m_pParentWnd->GetRpaProps()->m_StateReasonCtrl.SetCurSel(nID);
                        UpdateData(FALSE);
                }              
               
        }      
        CDialog::OnOK();
}

0
 
LVL 19

Accepted Solution

by:
LordOfPorts earned 500 total points
ID: 22698640
Can you try:

m_pParentWnd->GetRpaProps()->UpdateData(FALSE);

instead of:

UpdateData(FALSE);
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 22698768
>>To Andy: My ID is already unique, it already worked for the initialization.

What do you mean by initialisation?
Do you design the dialog then put some text into the static control in the resource editor?  eg. "This is my combo->"
0
 
LVL 8

Author Comment

by:rambovn
ID: 22700331
To Andy: I created the dialog, and by opening it at the 1st time, the static text is filled by the value that I got from the database.
After that, I clicked one button named Reset on this dialog, and tried to fill the static text with the new value, it didn't work. That's what I meant for initialization.
To LordOfPorts: it didn't work.

Thank you very much for your help.

I just want to give up :( But I have to solve it :-(

0
 
LVL 8

Author Comment

by:rambovn
ID: 22700367
To LordOfPorts: sorry, it tried with your last comment again and it worked :-) Now I can smile, it took me 2 days :-)
Thank you very much for your patience and your help again.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now