Click here to Skip to main content
15,891,375 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,
I have application where I showed text in multi-line but I want to show image in 1st column. But I want to know to how display images in 1st column.
Here is the code

C#
m_ListCtrl.SubclassDlgItem(IDC_LIST, this) ;
m_ListCtrl.SetNoOfLinesPerRow(2) ;
m_ListCtrl.SetNoOfColumns(2) ;
m_ListCtrl.SetNoOfRows(1) ;

void MyCtrl::OnInitializeX(MyCtrl &m_MyListCtrl) 
{	int i, j ;
	m_MyListCtrl.SetColumnHeader(_T("Student ID, 280"));

	LV_COLUMN lvc;
	lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM | LVCF_IMAGE;

	// Insert Header columns
	for(i = 0; i<m_ncolumns;>	{
		lvc.iSubItem = i;
		lvc.pszText = _gszColumnLabel[i];
		lvc.cx = _gnColumnWidth[i];
		lvc.fmt = _gnColumnFmt[i];
		InsertColumn(i,&lvc);
	}

	// Insert First Column items for every row
	LV_ITEM lvi;
	lvi.mask = LVIF_IMAGE | LVIF_TEXT ;

	char	buf[51] ;
	for(i=0; i<=m_nRows; i++)
	{
                 //Here I want to show image in first column and first row
		sprintf(buf, "Line 1 text \n lots a a \n more text") ;
		CString str = _T("Hi");
		str += _T("\r\n");
		str += _T("Hello");
		str += _T("\r\n");
		str += _T("How are you");
		lvi.iItem = i;
		lvi.iSubItem = 0;
		lvi.state = LVIS_SELECTED | LVIS_FOCUSED ;
		lvi.stateMask = LVIS_SELECTED | LVIS_FOCUSED ;
		//lvi.pszText = buf ;
		lvi.pszText = str.GetBuffer(str.GetLength()); 
		lvi.iImage = 2;
		InsertItem(&lvi);
                  //if (i == 0) m_nLinesPerRow = 3;
		//else m_nLinesPerRow = 5;

		for(j = 1; j<m_ncolumns;>		{
                     //Here Text is shown in Multi-line   			           SetItemText(i,j,str);
		}
	}

For this application the LVS_OWNERDRAWFIXED to true for CListCtrl.
Please let me know how can I show image to it.
Posted
Updated 9-Mar-13 9:11am
v2

1 solution

Take a look at this article VC++ MFC Tutorial: CListCtrl, InsertItem, Using List Control, SetImageList, Article with source code.[^]especially Chapter "Using Images":

// Create 256 color image lists
HIMAGELIST hList = ImageList_Create(32,32, ILC_COLOR8 |ILC_MASK , 8, 1);
m_cImageList.Attach(hList);

// Load the icons
CBitmap cBmp;
cBmp.LoadBitmap(IDB_IMAGES_NORMAL);
m_cImageList.Add(&cBmp, RGB(255,0, 255));
cBmp.DeleteObject();

// Attach them
m_MyListCtrl.SetImageList(&m_cImageList, LVSIL_NORMAL);
 
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