CMFCPropertyGridCtrl last item not drawn? - mfc

I have a CMFCPropertyGridCtrl that I'm using in an options dialog box. I have a method in my options dialog class called InitPropertyGrid(). This method clears any properties and populates the CMFCPropertyGrid objects (using a custom Settings object for the property values) and appends them to the grid.
When I open my dialog box the first time all the properties show correctly. However, if I then close my dialog box and reopen it, the very last property is not drawn on the screen. All other properties are drawn normally:
First time:
All subsequent times:
As you can see, the plus/minus icon is showing minus in both cases to indicated the section is expanded. When the last item is not showing, clicking on the +/- icon once to contract and once to expand causes the last item to be correctly shown.
Note when I close the dialog box, I do not destroy it but just reshow it. However immediately before calling ShowWindow on the dialog I call the InitPropertyGrid() (called by UpdateToCurrentSettings) method.
if(optionsDialog_ == NULL)
{
optionsDialog_ = new OptionsDialog(settings_, this);
optionsDialog_->Create(OptionsDialog::IDD, this);
}
optionsDialog_->UpdateToCurrentSettings();
optionsDialog_->ShowWindow(SW_SHOW);

I found I can eliminate this problem simply by calling myPropertyGrid.ExpandAll(TRUE) at the end of the code where I initialize the property grid (InitPropertyGrid() for me). This seems to force all the properties to expand.

Related

Unable to hide MFC controls in a CDialog derived class

I have a dialog that is derived from our specific base class that is inturn derived from CDialog class
This dialog contains a combobox with combobox items in it (string)
There is a group box, labels, checkbox and a text box as well (I will call them grouped controls for this discussion)
If I select an item in index 0 from combo box, the Grouped controls are shown and if I select an item in index 1 from combo box, the group controls should be hidden
I have used the code to show or hide the controls as
void MyDerivedClass::HideMyControls(bool hide)
{
int param = (false == hide)? SW_SHOW : SW_HIDE;
GetDlgItem(IDC_ENABLE_TP_DIRECTORY)->ShowWindow(param);//This is Checkbox control
GetDlgItem(IDC_STATIC_NOTE)->ShowWindow(param);//This is label control
GetDlgItem(IDC_STATIC_DIR_NAME)->ShowWindow(param);//This is label control
GetDlgItem(IDC_EDIT_TP_DIRECTORY)->ShowWindow(param);//This is text control
GetDlgItem(IDC_STATIC_TP_GRPBOX)->ShowWindow(param);//This is label control
InvalidateRect(NULL); //NULL for testing
UpdateWindow();
}
The issue is the controls are still seen on the screen even after the above method is called with true parameter. If I move some other window on top of the (supposed to be) hidden controls, then it is actually disappears. So this seems to be a refresh issue. My assumption is that the InvalidateRect and UpdateWindow should have taken care of repainitng this. but is not happening.
Tried with InvalidateRect(NULL) to paint the whole screen, but still no use.
Could you please suggest how I can hide the controls? any clean way of doing this?
Note: when the controls are (supposed to be) hidden but are still seen on the screen, I will not be able to perform any action on those controls (like setting checkbox or typing in the text box).
So I believe that the controls are marked as hidden but not painted.

OnInitDialog: reset dialog content

I have a PropertySheet containing 6 PropertyPages. During OnInitDialog of each page, a setting structure assigns initial values to the dialog controls.
However at some point, I want to change my setting structure and each dialog must show newly assigned values for each control it has. Like resseting every dialog.
To achive this, I tried removing and adding all 6 pages but it didn't work. How can I reset every dialog control without manually setting new values to controls.
If I can call OnInitDialog function it would work. However I cannot call OnInitDialog twice.

C++ MFC create new dialog and add Combobox item

I'm using MFC to build an application with two dialogs.
When I press a button in the parent dialog a new window including a Combobox should apprear.
I created a first dialog with a button "New". This button will open the second dialog.
Therefor I created a second dialog with a Combobox. The Combobox has a linked variable variableCombobox. The second class is called CSecond.
Before I do anything in the new dialog I want to add an item to the Combobox.
In the first dialog class I create the new window like this:
void CFirstDlg::OnBnClickedNew()
{
CSecond dlg2 = new CSecond();
dlg2.variableCombobox.AddString(L"test");
dlg2.DoModal();
}
The program crashes in the line I want to add the test string to the Combobox showing an assertion error.
I noticed that the dlg2 object is null but I don't know why.
Can anyone tell me how to create a second window immediately adding an new item in the Combobox of the second window?
The problem is the second dialog is a modal dialog. The windows does not exist before the call to DoModal() and no longer exist after that function returns. Therefore calling AddString on the combobox is not all right, since the combo box does not exist at that time.
The solution is to initialize the dialog with your desired values (like in the constructor for instance, or other methods) and then in OnInitDialog() use those values to setup the controls (including this call to AddString for the combobox).

How to minimize the page in the property sheet?

I have used property sheet concept and display 3 dialog box on the property sheet.
Now to access the each dialog i have to clicked on the tab of each dialog.
But my need is that i want to minimize the first dialog and show the second dialog without using tab. for that i have added one button using that button i minimized the first dialog but when i tried to call the second dialog i get assertion failed error. i have done like this...
In the 1st dialog (.cpp) file :
void ClstdemoDlg::OnBnClickedMinimize()
{
ClstdemoDlg_1 dlg; // created 2nd dialog variable.
this->ShowWindow(SW_MINIMIZE); // minimize the 1st dialog
dlg.ShowWindow(SW_SHOW); //Tried to show 2nd dialog but get Assertion failed Error
}
Please let me know how to do this?

How do I set focus to CEdit in child dialog that is inside TabCtrl?

I have a dialog box (CDialog) with owner-drawn CTabCtrl in it. Tabs content are child dialogs (one for each tab). There is an CEdit in each tab. When the user clicks a tab, I'm hiding all child dialogs using ShowWindow(SW_HIDE) and showing a selected one.
The problem is that when I have, for example, two tabs, click inside an edit box in the first tab and then switch to second, input focus stays on that (invisible) edit box in the first tab no matter what I do in my code (tried calling all methods that potentially can set focus, nothing changed).
Try this:
GetDlgItem(IDC_YOURCONTROL)->SetFocus();
Or the related variable linked with the control:
m_YOURCONTROLControl.SetFocus();