I have a list of item to be loaded in an MFC window with CListCtrl in it.
Upon OnInitDialog(), I will perform
m_List.InsertItem(&item);
where this item contains data such as: filename, last date modified, and comment.
The current output that I have now is that it will sort it with the last date modified when I open this dialog, then I would need to manually click on the list header to trigger an event to sort the data according to filename with functions such as below:
ON_NOTIFY(LVN_COLUMNCLICK, IDC_FILELIST, OnColumnclickFilelist)
int CALLBACK CDlg::AlphaNumericSorting(LPARAM lParam1, LPARAM lParam2, LPARAM ParameterSort)
{
std::wstring wv1(((CLVData*)lParam1)->strFileName);
std::wstring wv2(((CLVData*)lParam2)->strFileName);
return StrCmpLogicalW(wv1.c_str(), wv2.c_str()) < 0;
}
void Dlg::OnColumnclickFilelist(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
m_List.SortItems(AlphaNumericSorting, pNMListView->iSubItem);
*pResult = 0;
}
Now I'm trying to make it sort automatically upon OnInitDialog(), is there a correct way to do so? From what I searched so far, all samples I got are those with event handling.