Link to home
Start Free TrialLog in
Avatar of rambovn
rambovnFlag for Germany

asked on

IDC_STATIC Problem?

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

Avatar of LordOfPorts
LordOfPorts
Flag of United States of America image

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"));
Avatar of rambovn

ASKER

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
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

Avatar of rambovn

ASKER

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,
Avatar of rambovn

ASKER

Sorry you gave one solution but I thought there were 3 :-(
Avatar of rambovn

ASKER

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



Avatar of AndyAinscow
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.
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

...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
>> 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)
Avatar of rambovn

ASKER

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

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

Avatar of rambovn

ASKER

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

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.
Avatar of rambovn

ASKER

I already tried Updatedata (false); in OnRpaProperty() but it didn't work :-(
Avatar of rambovn

ASKER

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();


Can you post the syntax regarding how you called UpdateData(FALSE); in the OnRpaProperty()?

m_pRPAPropsDlg->UpdateData(FALSE); // ?
Avatar of rambovn

ASKER

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

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?
Avatar of rambovn

ASKER

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();
}

ASKER CERTIFIED SOLUTION
Avatar of LordOfPorts
LordOfPorts
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>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->"
Avatar of rambovn

ASKER

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 :-(

Avatar of rambovn

ASKER

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.