CListCtrl problem of Data Update

answerme's Avatar, Join Date: Dec 2007
Ambitious contributor
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);
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
It may be the case of Painting of the control and try giving an Invalidate to see if it updates after that,
0
answerme's Avatar, Join Date: Dec 2007
Ambitious contributor
ya i tried invalidate already as well as update also but still it is not working
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Then you are updating some other variable and not the one associated with the control which is visible.
0
answerme's Avatar, Join Date: Dec 2007
Ambitious contributor
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);
objLstCtrl.Invalidate();

strLstItem.Format("%f", longitude);
objLstCtrl.SetItemText(nItem, 2, strLstItem);
objLstCtrl.Invalidate();
But still cant fix out this bug
0
Gene Poole's Avatar, Join Date: Nov 2009
Contributor
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:
  int nItem=objLstCtrl.InsertItem(0,_T("Latitude:"));
  strLstItem.Format("%f", latitude);
  objLstCtrl.SetItemText(nItem, 1, strLstItem);
0
answerme's Avatar, Join Date: Dec 2007
Ambitious contributor
Here is the whole function iam pasting will it be help for u
Code:
void CEntityListView::AddEntityToList(int pPosition, TARGET_POS cursor)
int nItem;// =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
	{
		nItem = pPosition;
	}

                                latitude = cursor->L_Latitude;
				longitude = cursor->L_Longitude;

         strLstItem.Format("%f",latitude);
	objLstCtrl.SetItemText(nItem, 2, strLstItem);

	strLstItem.Format("%f", longitude);
	objLstCtrl.SetItemText(nItem, 3, strLstItem);
0
Gene Poole's Avatar, Join Date: Nov 2009
Contributor
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.