示例#1
0
BOOL MyListCtrl::init()
{
	//Create Image list. 
	
	m_ImageListThumb.DeleteImageList();
	m_IconWidth=2;
	m_IconHeight=27;
	m_ImageListThumb.Create(m_IconWidth, m_IconHeight, ILC_COLOR24, 0, 1);
	SetImageList(&m_ImageListThumb, LVSIL_SMALL);
	m_ShowIcons=FALSE;
	Arrange(LVSCW_AUTOSIZE);
	//LVSCW_AUTOSIZE
	FreeListItems();
	
	// For the resize problem...... 
	m_iNumberOfColumns=2;
	m_iColumnWidthArray[0]=60;
	m_iColumnWidthArray[1]=40;
	m_iColumnWidthArray[2]=110;
	m_iColumnWidthArray[3]=100;
	
	
	
	InsertColumn(0,"Name",LVCFMT_LEFT,m_iColumnWidthArray[0]);
	InsertColumn(1,"Address",LVCFMT_LEFT,m_iColumnWidthArray[1]);
	// nice flat list-  	
	SetExtendedStyle(LVS_EX_GRIDLINES | LVS_EX_FLATSB |
		LVS_EX_FULLROWSELECT );
	
	
	//
	// Setting the header INFO
	//
	
	// Loading header images.. 
	m_HeaderImages.DeleteImageList();
	m_HeaderImages.Create(IDB_HEADER, 9*2, 1, RGB(255,255,255));
	
	CHeaderCtrl* pHeader=GetHeaderCtrl();
	if(pHeader)
	{
		
		pHeader->SetImageList(&m_HeaderImages);
		
		for (int i=0; i < pHeader->GetItemCount(); i++)
		{
			SetHeaderIcon(i,-1);
		}
		
		SetBkColor(RGB(255,255,255));
		SetTextBkColor(RGB(255,255,255));
		SetTextColor(RGB(0,0,0));
		SetHeaderIcon(0,0);
		m_iCurrentSortColumn=0;
    }
	
	ResizeColumns();
	
	return TRUE;
}
示例#2
0
void MyListCtrl::OnColumnclick(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
	if(!pNMListView)
		AfxMessageBox(" C P Fel pNMListView= NULL");
	else
	{	
		if(m_iCurrentSortColumn==pNMListView->iSubItem)
		{
			m_sortdirection	=m_sortdirection*-1;
			if(m_sortdirection>0)
				SetHeaderIcon(pNMListView->iSubItem,0);
			else
				SetHeaderIcon(pNMListView->iSubItem,2);	
		}else
		{
			// Clear all the other Icons.. 
			for (int i=0; i < m_iNumberOfColumns; i++)
				SetHeaderIcon(i,-1);
			// Set the sortdirection 
			m_sortdirection=1;
			// change the icon direction 
			SetHeaderIcon(pNMListView->iSubItem,0);
			//Set the curren sort solumn 
			m_iCurrentSortColumn=pNMListView->iSubItem;

		}



		/*
		*	Sort the elements in the List. (NICE).. 
		*/

		if(m_sortdirection>=0)
			SortItems(CompareFunc, pNMListView->iSubItem);
		else
			SortItems(CompareFunc2, pNMListView->iSubItem);

		m_iCurrentSortColumn=pNMListView->iSubItem;

		*pResult = 0;
	}
}