user1634805
user1634805

Reputation: 11

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

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

Upvotes: 1

Views: 3342

Answers (2)

ScottMcP-MVP
ScottMcP-MVP

Reputation: 10415

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

Upvotes: 2

olevegard
olevegard

Reputation: 5532

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...

Upvotes: 1

Related Questions