Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 3 fields
C++
m_list.InsertColumn(0, _T("File Name"), LVCFMT_LEFT, 640);
m_list.InsertColumn(1, _T("Size"), LVCFMT_RIGHT, 120);
m_list.InsertColumn(2, _T("Item"), LVCFMT_RIGHT, 80);

When the fields are filled the File Name is on the left. When sorted it jumps the the right. How can I fix it?
Posted

1 solution

I found the answer, what I had, copied the justifymask from the column clicked. This version copies each column separately.
C++
// Display or hide sort icon on column to be sorted
void CFindWhatDlg::SetSortIcon()
{
	ASSERT(m_list);
	CHeaderCtrl* pHeaderCtrl = m_list.GetHeaderCtrl();
	ASSERT(pHeaderCtrl);
	
	HDITEM hdrItem;
	for (int nCol = 0; nCol < pHeaderCtrl->GetItemCount(); nCol++)
    {
		hdrItem.mask = HDI_FORMAT | HDI_IMAGE;
		pHeaderCtrl->GetItem(nCol, &hdrItem);
		if(bAscending)
		{
			hdrItem.iImage = m_nUpArrow;
			hdrItem.fmt    = hdrItem.fmt & HDF_JUSTIFYMASK |
				HDF_IMAGE | HDF_STRING| HDF_BITMAP_ON_RIGHT;
		}
		else
		{
			hdrItem.iImage = m_nDownArrow;
			hdrItem.fmt    = hdrItem.fmt & HDF_JUSTIFYMASK |
				HDF_IMAGE | HDF_STRING| HDF_BITMAP_ON_RIGHT;
		}
		pHeaderCtrl->SetItem(nCol, &hdrItem);
    }
}
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900