Listview tristate checkbox - c++

I have a listview in report style with checkboxes.
Is there any easy way to make the check box appear disabled? To give it a tristate sort of effect?
I want to have 3 states: Enabled, Disabled, and Unset.

The standard LVS_CHECKBOXES style does not support tri-state checkboxes. However, LVS_CHECKBOXES is internally implemented as a ListView-managed ImageList and normal ListView state indexes, so you can simply assign your own ImageList to the ListView, put three checkbox images into it, and set each ListView item's state index as needed. Then you just need to handle mouse messages for the ListView to switch between state indexes when clicking on an item's state image.

Related

Win32 (C++) :- How to make a list item collapsible

I have a listbox in which multiple list items are there. I want to implement something like if we click on the list item, it will collapse and show the summary of the clicked item:
I have been searching this on the web for quite sometime but haven't got any good solution. I am very new to Win32. Any suggestions on how to approach this like which control should I use. Any help will be appreciated.
Standard ListBox and ListView controls do not natively support expanding/collapsing items, however it is possible to implement it in a ListBox with some extra work.
Give the ListBox the LBS_OWNERDRAWVARIABLE list box style to allow the list to contain items of different heights. When a new item is added to the list, the ListBox will send a WM_MEASUREITEM message to its parent window asking for the item's initial height. Return an appropriate height based on whether the item should be displayed as collapsed or expanded.
Once an item has been added to the list, you can send the ListBox a LB_SETITEMHEIGHT message to assign a new height for that item based on whether it should now be displayed collapsed or expanded. Then invalidate the ListBox to trigger a repaint of the items.
The LBS_OWNERDRAW... styles require you to manually draw each list item whenever the ListBox sends a WM_DRAWITEM message to its parent window. You can draw the requested item on the provided HDC however you want, such as with the DrawText() function, configuring its parameters based on whether the item's text is currently being displayed as collapsed or expanded. Also use the state information provided by the message itself to configure the HDC's font and background/foreground colors as desired (particularly important when rendering items in the selected and focused states).
With that in place, all you have left to do is make your click handler determine the index of the item being clicked on (via GetMessagePos(), ScreenToClient(), and LB_ITEMFROMPOINT), and then assign it a new height based on its new expanded/collapsed state, and let the resulting repaint draw the new text accordingly.

How to change default widge styles?

I add field like
forms.ChoiceField(widget=forms.Select(choices=OPTIONS, initial=0)
when display, the normal dropdown is replaced with one with a search box on item list, I think that is Django widget?
I had to add the style to set wdith, otherwise, the dropdown will show with width 33px, way too small
But then I need embed those dropdowns into a jquery accordion. I found dropdowns in non-active section will all have width set to 0px. I guess widget set it to 0 after it detects them are hidden.
From A you can tell the dropdown has styles to make it have round corners
From B, you can see the dropdown doesn't show anything, from the html code, I see the width is set to 0px
If I don't apply the accordion, you see all three dropdowns are fine
I am looking for a way to solve this, either make widget not set width that way, or remove widget effect at all.
Any idea?
thanks

How to disable ListView select visual effect and draw a rectangle around item instead?

When a ListView item is selected, its color changes to indicate that it is selected. Now what I want to do is to disable this visual effect and implement my own, so for example I want when an item is selected to draw a rectangle around the item.
How can I do that? (Note that I am talking about the Icon view).
This is a case for custom drawing of controls.
It's all about handling the NM_CUSTOMDRAW notification and then to draw the control more or less by yourself.
I've never done it by myself changing the appearance seriously but I've change background colors of controls using this mechanism.
There is a lot of information about this on the internet...

how to set spacing between items and border color for items in ListView control(using C++ and win32api)

I successfully created thumbnail images using ListView control in win32 api and c++(No MFC).
I am struck up in proceeding with the below mentioned tasks.
I dont know what macros and styles to be applied to achieve the below tasks in listview control.
->how to align the items in listview control(LVS_LIST style)?
->how to set spacing between the items in listview control?
->how to set Border and border color for items in listview control and it should be highlighted on selecting the item in listview control.?
->After inserting the items in listview control,i have set vertical scroll bar but i get it as horizontal scroll bars.how to solve this also?
someone help me to achieve these tasks.
Thanks
Please see this set of window styles suitable for LVS_LIST:
List-View Window Styles
What about border color - consider LVS_OWNERDRAWFIXED.
And extended styles - Extended List-View Styles
Yet you can subclass window procedure for this control to manage LVM_GETITEMRECT, LVM_GETITEMPOSITION, LVM_SETITEMPOSITION messages differently.
And have a look over: NM_CUSTOMDRAW (list view) notification code
Yet don't forget to call InitCommonControlsEx() function before creating the ListView window.

Highlighting items in TreeView C++ BUILDER

How can i change text color of some specifec item in TreeView?
TreeView is filled in program.
I mean i want to highlight some Treeview item by changing it text color.
You need to owner-draw the TreeView. It has OnCustomDrawItem and OnAdvancedCustomDrawItem events for that purpose. On a per-item basis, you can set the TreeView's Canvas->Font->Color property to whatever you want. Since you have access to the Canvas, you can draw whatever you want, not just customize the text.