I'm trying to get the order of the columns in an MFC CListCtrl
. Initially I tried calling GetColumnOrderArray()
in a message handler for the HDN_ENDDRAG
notification, but that always returned the old (pre-drag and drop) column order. So, based on the advice in this SO post's comment, I tried handling both the HDN_BEGINDRAG
and the HDN_ENDDRAG
and grabbing the old and new column orders with phdr->pitem->iOrder
. But pitem
is always NULL for me in the both handlers. No idea why.
SOOO I tried using the column index stored in the message (phdr->iItem
) to talk directly to the CHeaderCtrl
and grab the column order myself, but the fields in the structure populated by my header control were all invalid; I still couldn't get the column order.
Is there some sort of deeper problem with my list control? Or am I just handling messages incorrectly?
HDN_BEGINDRAG
message handler:
BOOL CDFAManListView::OnHdnBegindrag(UINT, NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMHEADER phdr = reinterpret_cast<LPNMHEADER>(pNMHDR);
phdr->iItem; // this contains a valid column index
HDITEM columnStruct;
List->GetHeaderCtrl()->GetItem(phdr->iItem, &columnStruct); // but this call just fills columnStruct with junk values
if (phdr->pitem) // pitem is always null
{
initialPosition = phdr->pitem->iOrder;
}
*pResult = 0;
return TRUE;
}
HDN_ENDDRAG
message handler:
void CDFAManListView::OnHdnEnddrag(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMHEADER phdr = reinterpret_cast<LPNMHEADER>(pNMHDR);
HDITEM columnStruct;
List->GetHeaderCtrl()->GetItem(phdr->iItem, &columnStruct); // still just fills columnStruct with junk
List->GetColumnOrderArray(signalColumnOrder); // gets **old** column order
*pResult = 0;
}