Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Basic CListCtrl Question

Status
Not open for further replies.

fdsouth

Technical User
Jun 6, 2001
61
US
On pressing a button, I would like to move data from a 3 column CListCtrl to another 3 column CListCtrl. This is what I've done:

Code:
    CListCtrl *pChoices, *pSelected;
	pChoices = (CListCtrl *) GetDlgItem( IDS_CHOICES );
	pSelected = (CListCtrl *) GetDlgItem( IDS_SELECTED );

	CString sSerial;
	LVITEM lvi;

	lvi.mask = LVIF_TEXT;

	POSITION p = pChoices->GetFirstSelectedItemPosition();
	while (p)
	{
		int nSelected = pChoices->GetNextSelectedItem(p);
		lvi.iItem = nSelected;
		lvi.iSubItem = 0;
		lvi.pszText = (LPTSTR)(LPCTSTR)(sSerial);
		lvi.cchTextMax = 1024;
		pChoices->GetItem(&lvi);
		pSelected->InsertItem(&lvi);
		lvi.iSubItem = 1;
		pSelected->SetItem(&lvi);
	}

Inserting the item from column 1 works fine, but I can't get columns 2 and 3 to work. What am I missing??

Thanks in advance.
 
You only read the first column of every selected item and write it to another list control. I think you should add a loop to copy the next two columns.
 
I'm sorry. Could you show me some sample code for doing this? This control is new to me and I haven't figured out all the details yet (obviously).

Thanks
 

while (p)
{
int nSelected = pChoices->GetNextSelectedItem(p);
pSelected->InsertItem(nSelected,"");
for (int i=0;i<3;i++)
pSelected->SetItemText(nSlected,i,pChoices->GetItemText(nSlected,i));
}


 
Cool. That works great [fairly great :) that is]

When I press the button to copy the selected value to the other CListCtrl, the item previously selected (and copied) disappears and the new one appears 1 row below where the previous one was.

How do I keep the CListCtrl to &quot;remember&quot; the values already selected and just add to them?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top