Go4Expert

Go4Expert (http://www.go4expert.com/)
-   MFC (http://www.go4expert.com/forums/mfc/)
-   -   CListCtrl problem of Data Update (http://www.go4expert.com/forums/clistctrl-data-update-t20589/)

answerme 4Jan2010 14:26

CListCtrl problem of Data Update
 
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);


shabbir 4Jan2010 15:56

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,

answerme 4Jan2010 15:59

Re: CListCtrl problem of Data Update
 
ya i tried invalidate already as well as update also but still it is not working

shabbir 4Jan2010 18:26

Re: CListCtrl problem of Data Update
 
Then you are updating some other variable and not the one associated with the control which is visible.

answerme 5Jan2010 12:24

Re: CListCtrl problem of Data Update
 
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

Gene Poole 5Jan2010 19:09

Re: CListCtrl problem of Data Update
 
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);


answerme 6Jan2010 14:51

Re: CListCtrl problem of Data Update
 
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);


Gene Poole 6Jan2010 19:16

Re: CListCtrl problem of Data Update
 
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.


All times are GMT +5.5. The time now is 12:39.