Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MFC VC++
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
 
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 9-Mar-13 0:43am
SNI1.5K
Edited 9-Mar-13 10:11am
H.Brydon30.6K
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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);
  Permalink  
v3

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

  Print Answers RSS
0 OriginalGriff 341
1 Marcin Kozub 225
2 Sergey Alexandrovich Kryukov 220
3 Praneet Nadkar 197
4 Shweta N Mishra 161
0 OriginalGriff 8,149
1 Sergey Alexandrovich Kryukov 7,287
2 DamithSL 5,614
3 Manas Bhardwaj 4,986
4 Maciej Los 4,910


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 9 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100