CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 3 of 3 FirstFirst 123
Results 31 to 33 of 33

Thread: ListCtrl in MFC

  1. #31
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: ListCtrl in MFC

    Quote Originally Posted by GCDEF View Post
    As to the virtual list control, it's been a while for me, but I remember that as being a way to speed up performance of a list control with a lot of data. I'm not seeing how it helps with the OP's problem.
    It's the next evolution of using the list control
    1) The first is just copying the data into the control
    2) The next is getitemdataptr/setitemdataptr (items are still copied into the control, but a pointer is maintained to point back to the list item)
    3) The 3rd is a virtual list control where no data is copied into the control - instead there is a callback to retrieve the data directly from a list.

    I'm actually not trying to answer the OP's problem directly (I think that's been done). I'm trying to show essentially that there is more out there. Virtual list controls are kind of like the binding in modern (meaning, non-MFC or QT frameworks). I found it helpful to have understood virtual controls - it helped me understand data binding later on.

  2. #32
    Join Date
    May 2015
    Posts
    500

    Re: ListCtrl in MFC

    Thanks a lot Arjay, for all the help. Very much appreciated. I'll try this today

  3. #33
    Join Date
    May 2015
    Posts
    500

    Re: ListCtrl in MFC

    @GCDEF: May be I didnot code properly.
    What i understood is:, SetItemData can hold a reference to the index into the list control and a number. The number can be used later to deduce the first column info.

    Is this understanding correct ? Could you comment when you have bit spare time please

    Code:
    	int nItem = priya_list.InsertColumn(0, _T("Cell"), LVCFMT_LEFT, -1, 0);
    	priya_list.InsertColumn(1, _T("Site"), LVCFMT_LEFT, -1, 0);
    
    	int centralsite;
    	vector<int> sites;
    	bool bIsfirstCentralsite(false);
    	for (const auto pair : m)
    	{
    		bIsfirstCentralsite = true;
    		string centreId;
    		int index = pair.first;
    		if (index == 1)
    		{
    			centreId = "first";
    		}
    		else
    		{
    			centreId = "second";
    		}
    
    		CString ccetre(centreId.c_str());
    		for (const auto site : pair.second)
    		{
    			int nItem(0);
    			if (bIsfirstCentralsite)
    				nItem = priya_list.InsertItem(priya_list.GetItemCount(), ccetre);
    			else
    				nItem = priya_list.InsertItem(priya_list.GetItemCount(), _T(""));
    
    			auto itr = n.find(site);
    			string sSiteId = itr->second;
    			CString cSiteId(sSiteId.c_str());
    			priya_list.SetItemText(nItem, 1, cSiteId);
    
    			priya_list.SetItemData(nItem, (DWORD)(index));
    
    			bIsfirstCentralsite = false;
    
    		}
    	}
    And to retrieve this :

    Code:
    void CMFCApplication2Dlg::OnBnClickedAddToSiteDB()
    {
    
    	CListCtrl * priya_ctrl = (CListCtrl *) GetDlgItem(IDC_LIST1);
    
    	POSITION pos = priya_ctrl->GetFirstSelectedItemPosition();
    
    	int nItem = priya_ctrl->GetNextSelectedItem(pos);
    
    	int centreid = (int)priya_ctrl->GetItemData(nItem);
    
    }
    Last edited by pdk5; December 27th, 2020 at 05:05 AM.

Page 3 of 3 FirstFirst 123

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured