Disable items in a CheckedListBox in MFC - c++

Does CheckedListBox::Enable() to enable/disable items should behave like GetDlgItem(checkedbox)->EnableWindow(False), for a simple checkedbox, I mean for the last one, the item has the aspect of a disabled item, but for checkedlistbox the item has a normal aspect but I can't select it.
So is this normal for disable items from a CheckedListBox to not have a gray aspect?

Try to avoid using GetDlgItem
CCheckedListBox::Enable() is used to enable and disabled the individual checkbox in the list based on the index you pass into it.
EnableWindow is intended to enable or disable the entire control. In the case of a checkbox I would expect these to be similar however the CCheckedListBox may handle how it manages it's check box list items differently than how an independent checkbox control would behave.
You can probably override DrawItem and use owner drawn style if you want to do something different than the default behavior when updating visual aspects.

Related

How to add or remove textboxes by changing the options in the combobox in Visual c++?

I want to know that whether I can add a textbox or label by changing the options in combo box. For example, I have 2 options in Combobox. If I choose the #1, it must show me 2 textboxes, but if I choose #2 it must show 3 textboxes.Can I do something like this in Visual Studio C++?
This can be done in two ways:
Dynamically create and destroy the edit controls using CreateWindowEx and DestroyWindow.
Statically create your GUI with 3 edit controls and set the visibility of the controls based on the selection using ShowWindow.
Have as many text-boxes you want. But hide them.
Handle CBN_SELCHANGE (ON_CBN_SEL_CHANGE in MFC).
In the handler, show (or hide) the text boxes depending on selection.
Showing/hiding text boxes aren't good from UI perspective. You better enable/disable them appropriately. You may put alternate text when they are disabled, and bring back original change when they have to be enabled.
Creating textboxes at runtime, and then deleting them isn't' good approach. You will need to keep track of Win32 UI handle and/or MFC object. This approach will also need more of UI resource creation/deletion, parent-child relationship handling et. al.

Disable only specific list items in a win32 ListView

I am using win32, c++.
I have a ListView & i want to disable (grey out) only some of the items from the list.
Is that possible or only whole ListView can be greyed out?
The ListView control does not have a concept of disabled items. You can simulate that appearance using custom drawing support. This Sample demonstrates how to change the text and background color of items within the list view.
You would need to go further and provide some means of determining when a disabled item is selected within the view (as the selection will continue to work).
The Windows List View Common Control does not have a disabled state for Items. If you want to do that, you will have to implement it yourself.
This is a not-trivial exercise. It's not hard to change the visible appearance using customer draw, but handling hit-testing and selection would be quite complex.

Unlimited number of checkboxes

I wonder how to create mechanism which create new checkbox below previous when you click on button. Number of checkboxes are unlimited.
I don't think that table of objects work well, so I think about implementation in list of objects.
Any suggestions?
Here is what I would do:
Create an event for clicking that button (let's call it OnBtnClick)
Use a vector/list to hold all the checkboxes
When OnBtnClick is called you do:
create a checkbox with the desired position and size and make sure it receives an unique id (this will help you differentiate between checkboxes when they are clicked/checked/etc).
add the checkbox to the list (to get its status: checked or not checked)
add the checkbox to the desired window, the parent window (though this may happen automatically when you create it)
if you want to add an event for the added checkbox you should check the manual of your GUI framework (you will probably use the same event handler for all checkboxes and treat them separately based on their id)
Depending on the GUI framework used the bottom details may vary but the idea remains the same. I did this with wxWidgets, QT and MFC but I don't know which framework you use. You should be able to find code samples for each framework.
What would you do with unlimited number of check boxes - confuse the user? So, that he/she wouldn't attempt to use it again? Bad idea, as you can guess now.
You may (should) limit the number of check boxes (or better, limit the number of controls on form/dialog). IMO, more than 10-12 CBs would be cumbersome for the end user. Therefore, better idea is to have all of them on dialog/dialog-resource, and make all of them invisible/disabled. When user does some action, make them visible/enabled - so that end user may do something with it.
Still demand N number of CBs, where N is not determined beforehand? Then you may have checkboxes under Combo box, or use check-boxes under List Control. List Control already hosts this feature, but for CBs under Combo, you may need to write your own class.See this article as an example.

create a scrollbar in a submenu qt?

I have a map application and a submenu which has dynamically added objects (i.e. points on a map) added to the submenu, depending on the layer that is loaded. I have the ability to hide each individual objects (i.e. a point) by clicking on the corresponding submenu item. Is there any way to organize the submenu? When there are a lot of points (i.e. 100) the entire submenu takes up the screen. Can I add a scrollbar to a submenu? I looked in the documentation, but couldn't find anything that support this feature.
From this bug report I was able to find out that you could do the following:
submenu->setStyleSheet("QMenu { menu-scrollable: 1; }");
Works like a charm.
There is no such possibility as far as I know.
Maybe you shouldn't use a sub menu for this but prefer a menu entry that show a Point manager GUI of your own which would have a QListWidget displaying all your points items.
I'm aware that this solution will break a (big?) part of your code but I don't see anything else.
I think you may be able to get the effect you want by creating and using your own QStyle subclass (via QApplication::setStyle()), and overriding the styleHint virtual method to return 1 when the StyleHint parameter passed in is SH_Menu_Scrollable. At least, that works for me when I create large QMenu objects and show them as popup menus.... It may also work for QMenus attached to the menu bar, but I havent tried that.
Whilst it is possible by subclassing the QMenu class to create a custom widget and going from there you're better off looking at a better way to display that information. You'll save yourself time and it'll be much easier for your users to not have to scroll through a big list of items in a small area.

MFC - How can I disable a list item?

I have a CListCtrl with checkboxes. I want to be able to disable one of the items so that the user cannot click the checkbox. Is this possible? If so, how?
Edit:
Found the specifics on how to hide a checkbox in another question
Need only some rows in a CListCtrl control to have check boxes
Shortly: Not easily possible.
You'll need to sub-class the CListCtrl and implement this behavior on your own or download for example the MFC Grid Control that allows you to do that.
As for the removing check-boxes idea, yes, that might be possible, MSDN:
Version 4.70. Enables check boxes for items in a list-view control. When
set to this style, the control creates
and sets a state image list with two
images using DrawFrameControl. State
image 1 is the unchecked box, and
state image 2 is the checked box.
Setting the state image to zero
removes the check box.