I have a certain selection in combo box. Based on that selection some items need to be enabled/disabled. However I am unable to do so. And also another problem is once a single option is selected I cant change it to another selection without backspace and typing that selection again.
m_d_lvlayers
is the variable of IDC of combo box. Its type is CString
.
void CThermalToolDlg::OnCbnSelchangeLvLayers()
{
// TODO: Add your control notification handler code here
if (m_d_lvlayers == "2" )
{
UpdateData();
GetDlgItem(IDC_LV3_CU)->EnableWindow(0);
GetDlgItem(IDC_LV3_ICI)->EnableWindow(0);
//etc etc
UpdateData(0);
}
else if (m_d_lvlayers == "3")
{
UpdateData();
GetDlgItem(IDC_LV3_CU)->EnableWindow(1);
GetDlgItem(IDC_LV3_ICI)->EnableWindow(1);
//etc etc
UpdateData(0);
}
else
{
UpdateData();
GetDlgItem(IDC_LV3_CU)->EnableWindow(1);
GetDlgItem(IDC_LV3_ICI)->EnableWindow(1);
//etc etc
UpdateData(0);
}
}
I expect to get proper selections in combobox and corresponding enabling and disabling.
You need to call UpdateData(TRUE);
first .
bSaveAndValidate
Flag that indicates whether dialog box is being initialized (FALSE) or data is being retrieved (TRUE)
void CThermalToolDlg::OnCbnSelchangeLvLayers()
{
UpdateData(TRUE); // Controls to Variables
if (m_d_lvlayers == "2" )
{
GetDlgItem(IDC_LV3_CU)->EnableWindow(FALSE);
GetDlgItem(IDC_LV3_ICI)->EnableWindow(FALSE);
//etc etc
UpdateData(FALSE);
}
else if (m_d_lvlayers == "3")
{
GetDlgItem(IDC_LV3_CU)->EnableWindow(TRUE);
GetDlgItem(IDC_LV3_ICI)->EnableWindow(TRUE);
//etc etc
UpdateData(FALSE);
}
else
{
GetDlgItem(IDC_LV3_CU)->EnableWindow(TRUE);
GetDlgItem(IDC_LV3_ICI)->EnableWindow(TRUE);
//etc etc
UpdateData(FALSE);
}
}
Although in your code it makes no sense to call UpdateData(FALSE);
because all you are doing is setting the control window state to enabled.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.