[MFC]how to make disable an Item in combobox? - c++

I'm using Visual Studio 2012 with mfc standard library.
I want to make one Item is not able to be selected but Item can see in the list.
How can i do that? I'm a novice in MFC. plz help me
Though This is not a exact solution, I can make this.
When the Item is selected, there is no action and leave a message about the Item is invalid
So, If I just can change the color of the Item then, It's about to complete the function what I want. but I don't know even how to change color just one Item.
plz Give me a help!T.T

To change the color of just one item in a list box you have to completely replace the list box painting. You set the "owner draw" style and then write a message handler for WM_DRAWITEM. It will be called for each item in the list box. There are several examples at codeproject: here is one of them:
http://www.codeproject.com/Articles/135855/Owner-Drawn-CListBox

I don't think there is support for this in MFC.
But you can make your own list, that is derived from the MFC one. In that you can overload OnItemChange(NMHDR* pNMHDR, LRESULT* pResult) I think this is the one that's called when the user selects a different item in the list. You can then check what item is selected and give the user a warning saying "You can't select this item." I know it's not pretty, but I don't know of an other way...

Related

How can I sort Items in `CListCtrl` when the button is clicked?

How can I sort Items in CListCtrl when the button is clicked?
I made a Dialog based application in MFC.
I put CListCtrl control on my Dialog and set its view style to report type.
I have two columns in this list view.
In here when I clicked the "Sorting" button, it should sort item in the list.
I saw many examples related to this, but none is working for me.
Can some one guide me how to do that?
I assume that you mean the column header when you write "sorting button".
You probably forgot to put this into the message map of your dialog:
ON_NOTIFY(LVN_COLUMNCLICK, IDC_LIST1, OnColumnclickList1)
IDC_LIST1 is the id of the list control which may be different in your code.
Are you somewhat familiar with MFC ? If not, you should follow one of the numerous tutorials available on the net.
I would use a CMFCListCtrl. It is easier, as it as built in sorting functionality and you only have to provide a function with the comparing items algorithm for sorting. I have succeeded using it. You have to override the OnCompareItems on your class derived from CMFCListCtrl. I also recommend you to do a call to EnableMarkSortedColumn(); after your list is created.
The CListCtrl has a SortItems method.
All you need to do is provide your Compare function to it as the parameter.
I don't know much about the contents of your list control so I can't really give you more information.
Please read up on it and extend your question with example code and details of which column needs to be sorted and I can help more.
If the contents of your cells are just text then I usually just return the value of:
return Value1.CollateNoCase(Value2);
There are also lots of tutorials on the Internet. For example:
http://www.codeproject.com/Articles/27774/CListCtrl-and-sorting-rows
In fact, that tutorial suggests us in SortItemsEx. That is what I would use.

UltraComboEditor - Infragistics control

I have an UltraComboEditor (Infragistics control) and the user can input values on it. I used the AutoComplete property to do that.
But now I have a problem. I need to make sure that my user can delete a value that he wrote. I use the function canUndo but it not works.
How can I solve my problem?
Thank you.
I will try to add a ButtonLeft element, perhaps with a red cross image.
Let the user select an item from the combobox and then he/she will press the button element to trigger the action to delete the current selected element.
In the EditorButtonClick event you should ask for a confirm, search into your items collection and then remove the one selected.

custom combobox win32

I am trying to implement an auto-suggest feature in an win32 combobox (C++). I want to achieve a behaviour that is similar to the google auto suggest function. When the user types something into the edit-control of the combobox, its listbox opens and shows all possible matches. The Problem is the default behaviour of a win32 combobox is to always select the closest match and put the complete text (selected) into the edit control when the list is opened. I need to avoid this behaviour. The list should just open - dont select something and dont change the text in the edit-control!
I have tried to subclass the combobox and catch the CBN_DROPDOWN message, but this changes nothing on the default behavior.
Does anyone have a further idea? I dont want the auto-complete feature that just completes the text in the edit-control without opening the list.
Thx in advance
Greets, Michael

MFC: How to determine the currently HIGHLIGHTED item in a CComboBox list (NOT selected item)

This is similar BUT NOT THE SAME as C# questions, but as everyone knows, MFC is not .NET. MFC objects do NOT have the same runtime properties as .NET objects.
By using the Owner Draw mechanism (even though it's a simple text list), the callback has flags/attributes that shows which entry needs to be "highlighted", which we post a notification as to which item is currently "highlighted".
The complexity was MUCH less than trying to implement basic ComboBox functionality in a ComboBoxEx control (e.g. basic ComboBox styles do NOT apply to ComboBoxEx - don't ask).
I don't know if it would be of much help but....every time the highlighted item changes you receive a CB_GETCOMBOBOXINFO message.
I don't thik the information you receive with this message is going to help but if you really need to know the highlighted item maybe you could calculate it based on the mouse position and the height of every item. A bit tricky but possible.
I hope it helps.

MFC ctrls and duplicate messages

I have two CListCtrl objects in my form. I want selected list in both of them be same.
How I can do it.
I want duplicate the message that sent to a ClistCtrl and send to other one.
How I can do it?
if this is a good way?
thanks herzl
So, essentially what you're saying is that you want the lists to be synchronized.
You can easily achieve that by adding an event handler to catch the user's selection inside you list control, by adding: ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST1, OnItemChangedList1) to your dialog/window's message-map.
Inside OnItemChangedList1(), get the index of the currently selected item by calling GetFirstSelectedItemPosition(), and set that as the current index in your second list by calling SetSelectionMark().
This way, whenever the user will click on the 2nd item, for example, in List_A, the 2nd item in List_B will be selected as well.
There ought to be a function that brings that row into view, if it's not in view already, but I can't find it.
I hope that raps it up, ListView's have changed a lot since I've used them, but feel free to ask more if anything is unclear.