15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


CTreeView: Weird sorting/data retrieval interaction behaviou

rwagner -- rwagner@genre.com
Tuesday, November 05, 1996





          Environment: VC++ 4.2-flat / Win 95 / MSDN / brain

          When I add items to a node in a tree control with sorting turned
          on, I don't get the same data out that I stored there with
          SetItemData().  What I get out is the data that WOULD have been
          stored at that location had I not sorted the tree... in other
          words, the SetItemData/GetItemData scheme for storing a pointer
          in the tree works perfectly if my call to InsertItem (see below)
          uses the TVI_LAST flag instead of the TVI_SORT flag.

          Therefore, the first item added below the parent node's label is
          "ZZZZZZ", and I store associated data 0x12345678 there, AND I use
          the TVI_SORT parameter.  I than add   a node with label, "AAAAAA"
          with associated data 0x87654321.  "AAAAAA" appears first.  The
          user clicks on node "AAAAAA", and gets "ZZZZZZ"'s data, because I
          stored "ZZZZZZ" first!

          Weird.  I wonder what is REALLY happening here.  Is there a
          better way to do this?  I have no choice about the sorting: the
          data comes in from the database in an unpredictable order and the
          nodes must be ordered by label.

          Here is the code.  In a class that I derive from a class that I
          derive from CTreeView, I add several items to one item, with the
          sort flag, in the following manner:

          myTreeView::populateTree( void )
          {
              myTreeCtrl& treeControl = (myTreeCtrl&)(GetTreeCtrl());
              for(...)
              {
                  HTREEITEM node = treeControl.InsertItem(
                      (LPCTSTR)(pObject->GetLabel()),
                      image, image+1, parent_hTreeItem, TVI_SORT );

          // ... I then store a pointer to pObject,
          //     which is of a class derived from CObject, in the node:
                  treeControl.SetItemData( node, reinterpret_cast
          (pObject) );
              }
          }
          // ... and retrieve it later in OnSelchanged() with calls to:

                  HTREEITEM node = treeControl.GetSelectedItem()
                  reinterpret_cast(treeControl.GetItemData(node));

          Any ideas?

          Cheers
          Rob Wagner
          Sr. Software Engineer
          PSW Technologies





Todd Foster -- foster@media.philips.com
Thursday, November 07, 1996

Check out the article in M$ Systems Journal (dec96).
Jeff Prosise's article, Wicked Code, is about a sortable
list view control class.  ftp:\\ftp.microsoft.com /developr/MSJ directory,
or www.msj.com.  Good luck.

----------
From: 	rwagner@genre.com[SMTP:rwagner@genre.com]
Subject: 	CTreeView: Weird sorting/data retrieval interaction behaviour
          Environment: VC++ 4.2-flat / Win 95 / MSDN / brain

          When I add items to a node in a tree control with sorting turned
          on, I don't get the same data out that I stored there with
          SetItemData().  What I get out is the data that WOULD have been
          stored at that location had I not sorted the tree... in other
          words, the SetItemData/GetItemData scheme for storing a pointer
          in the tree works perfectly if my call to InsertItem (see below)
          uses the TVI_LAST flag instead of the TVI_SORT flag.

          Therefore, the first item added below the parent node's label is
          "ZZZZZZ", and I store associated data 0x12345678 there, AND I use
          the TVI_SORT parameter.  I than add   a node with label, "AAAAAA"
          with associated data 0x87654321.  "AAAAAA" appears first.  The
          user clicks on node "AAAAAA", and gets "ZZZZZZ"'s data, because I
          stored "ZZZZZZ" first!

          Weird.  I wonder what is REALLY happening here.  Is there a
          better way to do this?  I have no choice about the sorting: the
          data comes in from the database in an unpredictable order and the
          nodes must be ordered by label.

          Here is the code.  In a class that I derive from a class that I
          derive from CTreeView, I add several items to one item, with the
          sort flag, in the following manner:

          myTreeView::populateTree( void )
          {
              myTreeCtrl& treeControl = (myTreeCtrl&)(GetTreeCtrl());
              for(...)
              {
                  HTREEITEM node = treeControl.InsertItem(
                      (LPCTSTR)(pObject->GetLabel()),
                      image, image+1, parent_hTreeItem, TVI_SORT );

          // ... I then store a pointer to pObject,
          //     which is of a class derived from CObject, in the node:
                  treeControl.SetItemData( node, reinterpret_cast
          (pObject) );
              }
          }
          // ... and retrieve it later in OnSelchanged() with calls to:

                  HTREEITEM node = treeControl.GetSelectedItem()
                  reinterpret_cast(treeControl.GetItemData(node));

          Any ideas?

          Cheers
          Rob Wagner
          Sr. Software Engineer
          PSW Technologies





------ =_NextPart_000_01BBCCB7.3E559C20
Content-Type: application/ms-tnef



rwagner -- rwagner@genre.com
Monday, November 11, 1996





          > That is very, very wierd, and very, very wrong.
          I thought it was me.  I had somebody else duplicate this today.

          However, it disappears if I seperate out the calls so that the
          insert
          is done with the TVI_LAST flag instead of TVI_SORT, and then I
          call
          SortChildren() outside the loop, when I'm done:
          for(...)
          {
              HTREEITEM node = tC.InsertItem(
                  (LPCTSTR)(pObject->GetLabel()),
                  image, image+1, parent, TVI_LAST ); // bugg: TVI_SORT );
              tC.SetItemData( node, reinterpret_cast(pObject) );
          }
          tC.SortChildren( parent );

          >  If your analysis is correct, then it is most definately a bug in
          the
          COMCTRL32.DLL file.   I wonder if you have a beta version of that
          DLL or something like that?

          Standard 4.2 via subscription, according to the MIS Moghuls who
          installed it at the client site here.  However, the way Microsoft
          treated
          the last bug I approached them with, they turned it into a 'feature'
          so
          I hope that it is sufficient to warn the list that TVI_SORT and
          SetItemData() do NOT mix !!!

          Best,
          Rob






| Вернуться в корень Архива |