Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. trouble with UpdateAllViews()

trouble with UpdateAllViews()

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Trucker
    wrote on last edited by
    #1

    Hi, I have an SDI Application with 3 views: CLeftView, CTopRightView, CBottomRightView. CTopRightView has a CListCtrl. In the code for CLeftView, if some condition is met, I want to add an item to the list control in CTopRightView. To do this, in CLeftView I set a Doc var to the item i want to add. Next, I call UpdateAllViews() so it can call my Overridden OnUpdate functions in my views. My overriden OnUpdate function in CtopRightView adds the item set in Doc class to the list control. The Problem: UpdateAllViews() seems to call OnCreate() before it calls my OnUpdate function, thus clearing all the contents I had in the list control, and then calls OnUpdate(). Is there any way to prevent it from calling the OnCreate()? I don't want to recreate the list control, just add an item to it.:~ TraileR ParK LifE 4Ever

    M D 2 Replies Last reply
    0
    • T Trucker

      Hi, I have an SDI Application with 3 views: CLeftView, CTopRightView, CBottomRightView. CTopRightView has a CListCtrl. In the code for CLeftView, if some condition is met, I want to add an item to the list control in CTopRightView. To do this, in CLeftView I set a Doc var to the item i want to add. Next, I call UpdateAllViews() so it can call my Overridden OnUpdate functions in my views. My overriden OnUpdate function in CtopRightView adds the item set in Doc class to the list control. The Problem: UpdateAllViews() seems to call OnCreate() before it calls my OnUpdate function, thus clearing all the contents I had in the list control, and then calls OnUpdate(). Is there any way to prevent it from calling the OnCreate()? I don't want to recreate the list control, just add an item to it.:~ TraileR ParK LifE 4Ever

      M Offline
      M Offline
      MailtoGops
      wrote on last edited by
      #2

      UpdateAllViews() should not call OnCreate() method. Could you please make sure, you have created all views and initialized before calling UpdateAllViews() method. Show us some code snipet.. " Action without vision is only passing time, Vision without action is merely day dreaming, But vision with action can change the world " - Words from Nelson Mandela Thanks & Regards, Gopalakrishnan

      T 1 Reply Last reply
      0
      • T Trucker

        Hi, I have an SDI Application with 3 views: CLeftView, CTopRightView, CBottomRightView. CTopRightView has a CListCtrl. In the code for CLeftView, if some condition is met, I want to add an item to the list control in CTopRightView. To do this, in CLeftView I set a Doc var to the item i want to add. Next, I call UpdateAllViews() so it can call my Overridden OnUpdate functions in my views. My overriden OnUpdate function in CtopRightView adds the item set in Doc class to the list control. The Problem: UpdateAllViews() seems to call OnCreate() before it calls my OnUpdate function, thus clearing all the contents I had in the list control, and then calls OnUpdate(). Is there any way to prevent it from calling the OnCreate()? I don't want to recreate the list control, just add an item to it.:~ TraileR ParK LifE 4Ever

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        For an SDI application, this is normal behavior. When a view asks the document for the data to be rendered, it has the choice of adding only new items, or adding all the items (again). I prefer the latter as it is much easier to clear the list control and add all of the items, contrasted with figuring out which items in the document are already in the view's list and which are not. The MSDN article Q103982 might be remotely related to what you are seeing.


        "One must learn from the bite of the fire to leave it alone." - Native American Proverb

        T 1 Reply Last reply
        0
        • D David Crow

          For an SDI application, this is normal behavior. When a view asks the document for the data to be rendered, it has the choice of adding only new items, or adding all the items (again). I prefer the latter as it is much easier to clear the list control and add all of the items, contrasted with figuring out which items in the document are already in the view's list and which are not. The MSDN article Q103982 might be remotely related to what you are seeing.


          "One must learn from the bite of the fire to leave it alone." - Native American Proverb

          T Offline
          T Offline
          Trucker
          wrote on last edited by
          #4

          Hi David, Thanks for the reply. So how would I specify that I want the View to add only new items? The article refers to VC++ 6.1 and older. I am using VC++ .NET. I did not find OnInitialUpdate() function in the .NET Framework for CView, which they talk about in the article. TraileR ParK LifE 4Ever

          D 1 Reply Last reply
          0
          • T Trucker

            Hi David, Thanks for the reply. So how would I specify that I want the View to add only new items? The article refers to VC++ 6.1 and older. I am using VC++ .NET. I did not find OnInitialUpdate() function in the .NET Framework for CView, which they talk about in the article. TraileR ParK LifE 4Ever

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            /*Trucker*\ wrote: So how would I specify that I want the View to add only new items? How many total items are we talking about here? /*Trucker*\ wrote: The article refers to VC++ 6.1 and older. I am using VC++ .NET. I did not find OnInitialUpdate() function in the .NET Framework for CView, which they talk about in the article. That's why I indicated it might only be remotely related. :-D


            "One must learn from the bite of the fire to leave it alone." - Native American Proverb

            T 1 Reply Last reply
            0
            • M MailtoGops

              UpdateAllViews() should not call OnCreate() method. Could you please make sure, you have created all views and initialized before calling UpdateAllViews() method. Show us some code snipet.. " Action without vision is only passing time, Vision without action is merely day dreaming, But vision with action can change the world " - Words from Nelson Mandela Thanks & Regards, Gopalakrishnan

              T Offline
              T Offline
              Trucker
              wrote on last edited by
              #6

              Hi MailToGops, Thanks for the reply. All views are created and initialized. Below is some code you requested of what I am trying to do: in CLeftView: GetDocument()->FileAction(&strFileName,1); in Doc class: void Ca1interfaceDoc::FileAction(CString* fl, int acn) { fileName = *fl; action = acn; SetModifiedFlag(); UpdateAllViews(NULL); fileCount++; } in CTopRightView: int CTopRightView::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CView::OnCreate(lpCreateStruct) == -1) return -1; //creating listview folderContents.Create(WS_VISIBLE|WS_CHILD|WS_BORDER| LVS_LIST|LVS_SINGLESEL, CRect(10,10,300,180), this, IDC_FOLDERCONTENTS); LV_ITEM lvItem; ::memset(&lvItem, 0, sizeof(LV_ITEM)); lvItem.mask = LVIF_TEXT|LVIF_STATE; lvItem.state = 0; lvItem.stateMask = 0; lvItem.pszText = "an item"; lvItem.iItem = 0; folderContents.InsertItem(&lvItem); return 0; } void CTopRightView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) { //folderContents.DeleteAllItems(); if(GetDocument()->action == 1 /*&& !GetDocument()->fileCount*/){ LV_ITEM lvItem; ::memset(&lvItem, 0, sizeof(LV_ITEM)); lvItem.mask = LVIF_TEXT; lvItem.pszText = GetNTS(GetDocument()->fileName); lvItem.iItem = GetDocument()->fileCount; if(folderContents.InsertItem(&lvItem) == -1) folderContents.DeleteAllItems(); GetDocument()->action = 0; } } The reason I believe OnCreate gets called every time UpdateAllViews() runs is this: *In CTopRightView::OnCreate() I create the list control along with a test item and add this test item. *When I run the application I only see 2 items in the CTopRightViews's list control. The test item added in OnCreate() and the last item that was supposed to be added to the list control (many items are supposed to be added to the list control). So it looks like every time UpdateAllViews is executed it recreates the list control with the test item and the most recent item to be added.:^) TraileR ParK LifE 4Ever

              1 Reply Last reply
              0
              • D David Crow

                /*Trucker*\ wrote: So how would I specify that I want the View to add only new items? How many total items are we talking about here? /*Trucker*\ wrote: The article refers to VC++ 6.1 and older. I am using VC++ .NET. I did not find OnInitialUpdate() function in the .NET Framework for CView, which they talk about in the article. That's why I indicated it might only be remotely related. :-D


                "One must learn from the bite of the fire to leave it alone." - Native American Proverb

                T Offline
                T Offline
                Trucker
                wrote on last edited by
                #7

                I am not sure why this is relevent but anyways... to give you an idea I will tell u what my application is. It is Like Windows Explorer. So left pane is the directory tree, but the right pane holds just the files of selected folder in directory tree (dont worry about the third pane I mentioned earlier). So it could be a little, or it could be a lot of files/items... but lets say it shouldn't be too much because this is just an assignment for school I am doing, not some program for Bill Gates:laugh: TraileR ParK LifE 4Ever

                D 1 Reply Last reply
                0
                • T Trucker

                  I am not sure why this is relevent but anyways... to give you an idea I will tell u what my application is. It is Like Windows Explorer. So left pane is the directory tree, but the right pane holds just the files of selected folder in directory tree (dont worry about the third pane I mentioned earlier). So it could be a little, or it could be a lot of files/items... but lets say it shouldn't be too much because this is just an assignment for school I am doing, not some program for Bill Gates:laugh: TraileR ParK LifE 4Ever

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #8

                  I really don't know of a reason to not do it the way I previously suggested, especially for the volume of items you've indicated. It's just a much smoother approach to a fairly common doc/view situation. I'm curious why you are creating the list views each time they need updating. That's seems a bit inefficient. Why not create them once at the start of the application, and then update their contents as the need arises? With MFC, this is very easy to do using CSplitterWnd.


                  "One must learn from the bite of the fire to leave it alone." - Native American Proverb

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups