Retaining selection on a ListCtrl Item
-
Hello all, I have a dialog with a ListControl and some other buttons and edit boxes. The ListControl has bunch of items in it. Now when the user clicks on one item in the ListControl, that particular item gets highlighted in blue color. After the selection if user goes on to click on a edit box or buttons then the blue selection color disappears. Is it possible to persist with the color even though user clicks on other controls in the same dialog? How to do that? Thanks in advance.
-
Hello all, I have a dialog with a ListControl and some other buttons and edit boxes. The ListControl has bunch of items in it. Now when the user clicks on one item in the ListControl, that particular item gets highlighted in blue color. After the selection if user goes on to click on a edit box or buttons then the blue selection color disappears. Is it possible to persist with the color even though user clicks on other controls in the same dialog? How to do that? Thanks in advance.
In the dialog resource editor, right-click the list control and select Properties. Set the "Always Show Selection" property to TRUE. That's it. I don't know why the default is not TRUE for this property - I always end up setting it like that. Soren Madsen
"When you don't know what you're doing it's best to do it quickly" - Jase #DuckDynasty
-
In the dialog resource editor, right-click the list control and select Properties. Set the "Always Show Selection" property to TRUE. That's it. I don't know why the default is not TRUE for this property - I always end up setting it like that. Soren Madsen
"When you don't know what you're doing it's best to do it quickly" - Jase #DuckDynasty
That doesn't work. I am looking for something by which the blue highlight will stay on the list item.
-
That doesn't work. I am looking for something by which the blue highlight will stay on the list item.
Donguy1976 wrote:
I am looking for something by which the blue highlight will stay on the list item.
Yes, that is what that property does for you. Actually, it should be shown as gray, not blue to indicate the does not have focus, but at least it shows the selection. Do you by any chance override the list control styles during initialization? If so, you should include LVS_SHOWSELALWAYS. Soren Madsen
"When you don't know what you're doing it's best to do it quickly" - Jase #DuckDynasty
-
Donguy1976 wrote:
I am looking for something by which the blue highlight will stay on the list item.
Yes, that is what that property does for you. Actually, it should be shown as gray, not blue to indicate the does not have focus, but at least it shows the selection. Do you by any chance override the list control styles during initialization? If so, you should include LVS_SHOWSELALWAYS. Soren Madsen
"When you don't know what you're doing it's best to do it quickly" - Jase #DuckDynasty
I want it to be BLUE and not GRAY. Anyone know how to do that?
-
I want it to be BLUE and not GRAY. Anyone know how to do that?
Things like that are normally done by overloading the list controls
OnCustomdraw()
. To do this, you use your own class derived fromCListCtrl
. If you want more information on that, check this (or you can Google): http://msdn.microsoft.com/en-us/library/ms364048(v=vs.80).aspx[^] Here is anOnCustomdraw()
I copied from existing code and modified to do what you want it to do (hopefully). It is untested, so I don't actually know if it will work correctly (or even compile), but go ahead and try it out.void CYourListCtrl::OnCustomdraw(NMHDR* pNMHDR, LRESULT* pResult)
{
NMLVCUSTOMDRAW* pLVCD = reinterpret_cast( pNMHDR );// Take the default processing unless we set this to something else below. \*pResult = 0; // First thing - check the draw stage. If it's the control's prepaint // stage, then tell Windows we want messages for every item. if ( CDDS\_PREPAINT == pLVCD->nmcd.dwDrawStage ) { \*pResult = CDRF\_NOTIFYITEMDRAW; } else if ( CDDS\_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage ) { // This is the prepaint stage for an item. Here's where we set the // item's text color. Our return value will tell Windows to draw the // item itself, but it will use the new color we set here. // Do not apply special behavior if the list control is disabled. if (IsWindowEnabled()) { int nItem = (int)pLVCD->nmcd.dwItemSpec; // Always draw the selected item with the highlight color. if (GetItemState(nItem, LVIS\_SELECTED | LVIS\_FOCUSED) != 0) { // Store the color back in the NMLVCUSTOMDRAW struct. pLVCD->clrText = GetSysColor(COLOR\_HIGHLIGHTTEXT); pLVCD->clrTextBk = GetSysColor(COLOR\_HIGHLIGHT); // Tell Windows to paint the control itself. \*pResult = CDRF\_DODEFAULT; } } }
}
Soren Madsen
"When you don't know what you're doing it's best to do it quickly" - Jase #DuckDynasty