1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

CListCtrl problem of Data Update

Discussion in 'MFC' started by answerme, Jan 4, 2010.

  1. answerme

    answerme New Member

    Joined:
    Dec 17, 2007
    Messages:
    114
    Likes Received:
    0
    Trophy Points:
    0
    Hi all
    Iam facing problem in listview .Problem is while giving breakpoint I can see values are getting updated but when i am seeing LISTVIEW in my application ,its not getting updated.


    Code:
    
    Code Below iam giving breakpoints latitude & longitude values are changing but when i run my application in Listview latitude & longitude are not changing. I try to give invalidate() as well as update but it did not worked it out 
    
    
    CString strLstItem;
    CListCtrl &objLstCtrl = GetListCtrl();
    
    strLstItem.Format("%f", latitude);
    objLstCtrl.SetItemText(nItem, 1, strLstItem);
    
    strLstItem.Format("%f", longitude);
    objLstCtrl.SetItemText(nItem, 2, strLstItem); 
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,287
    Likes Received:
    364
    Trophy Points:
    83
    Re: CListCtrl problem

    It may be the case of Painting of the control and try giving an Invalidate to see if it updates after that,
     
  3. answerme

    answerme New Member

    Joined:
    Dec 17, 2007
    Messages:
    114
    Likes Received:
    0
    Trophy Points:
    0
    ya i tried invalidate already as well as update also but still it is not working
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,287
    Likes Received:
    364
    Trophy Points:
    83
    Then you are updating some other variable and not the one associated with the control which is visible.
     
  5. answerme

    answerme New Member

    Joined:
    Dec 17, 2007
    Messages:
    114
    Likes Received:
    0
    Trophy Points:
    0
    No Shabbir
    I am updating that variable only because i can see while giving breakpoint value are getting updated

    Code:
    CString strLstItem;
    CListCtrl &objLstCtrl = GetListCtrl();
    
    strLstItem.Format("%f", latitude);
    objLstCtrl.SetItemText(nItem, 1, strLstItem);
    [B]objLstCtrl.Invalidate();[/B]
    
    strLstItem.Format("%f", longitude);
    objLstCtrl.SetItemText(nItem, 2, strLstItem);
    [B]objLstCtrl.Invalidate();[/B]
    But still cant fix out this bug
     
  6. Gene Poole

    Gene Poole New Member

    Joined:
    Nov 10, 2009
    Messages:
    93
    Likes Received:
    5
    Trophy Points:
    0
    Are you actually adding an item to the list first? You can't set an item's text until there is an item in the list. Where is nItem coming from? There should be a call somewhere like:

    Code:
    
      [COLOR="Red"]int nItem=objLstCtrl.InsertItem(0,_T("Latitude:"));[/COLOR]
      strLstItem.Format("%f", latitude);
      objLstCtrl.SetItemText(nItem, 1, strLstItem);
    
     
  7. answerme

    answerme New Member

    Joined:
    Dec 17, 2007
    Messages:
    114
    Likes Received:
    0
    Trophy Points:
    0
    Here is the whole function iam pasting will it be help for u
    Code:
    void CEntityListView::AddEntityToList(int pPosition, TARGET_POS cursor)
    int [B]nItem[/B];// =0;
    	CString strLstItem;
    	CListCtrl &objLstCtrl = GetListCtrl();
    	
    
    	int nLstCount = objLstCtrl.GetItemCount(); //(r)Retrieves the number of items in a list view control.
    
    	if(nLstCount == 0)
    	{
    		POSITION position;
    
    		position = ((CScenGenDoc*)m_pDocument)->GetFirstViewPosition();
    		while(position != NULL)
    		{
    			CView *pView = ((CScenGenDoc*)m_pDocument)->GetNextView(position);
    			if(pView->IsKindOf(RUNTIME_CLASS(CEntityDetailInfoView)))
    			{
    				((CEntityDetailInfoView*)pView)->SetEntityIndex(1);
    			}
    		}
    	}
    
    	if(pPosition > nLstCount)
    	{
    		strLstItem.Format("%6d", pPosition);
    		nItem = objLstCtrl.InsertItem(nLstCount, strLstItem);
    	}
    	else
    	{
    		[B]nItem [/B]= pPosition;
    	}
    
                                    latitude = cursor->L_Latitude;
    				longitude = cursor->L_Longitude;
    
             strLstItem.Format("%f",latitude);
    	objLstCtrl.SetItemText([B]nItem[/B], 2, strLstItem);
    
    	strLstItem.Format("%f", longitude);
    	objLstCtrl.SetItemText([B]nItem[/B], 3, strLstItem);
     
  8. Gene Poole

    Gene Poole New Member

    Joined:
    Nov 10, 2009
    Messages:
    93
    Likes Received:
    5
    Trophy Points:
    0
    I certainly don't see anything there that looks out of place. Are there any warnings or anything else that might indicate some other problem? I'm at a loss at this point.
     

Share This Page