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. ListCtrl: maintain the slection after repopulating it...

ListCtrl: maintain the slection after repopulating it...

Scheduled Pinned Locked Moved C / C++ / MFC
questionannouncementcode-review
4 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.
  • J Offline
    J Offline
    Joan M
    wrote on last edited by
    #1

    Hello, INTRODUCTION: I'm using a normal CListCtrl in a dialog based app. When I update/edit a value in the ListCtrl (REPORT MODE) I validate it versus all the other values (they must follow some rules) and if some are not as they should have to be, I modify the variables that are linked to those parameters and then I re-populate ALL the ListCtrl reading those variables... NOTE: I know that this is not the best method... but it works and I have no time to improve it... moreover there are only 8 elements in the ListCtrl. :-O QUESTION: In order not to fool the user I want to be able to place the selection where it was (over the last edited item). The fact is that I can see the selection mark over the desired element, but when I press the down arrow the selection gets placed over the first element. :confused: After the edition I'm using this code now: if (iElement == -1) iElement = this->m_ElementModificatAct.m_iItemActual; this->SetItemState(iElement, LVIS_SELECTED, LVIS_SELECTED | LVIS_FOCUSED); this->EnsureVisible(iElement, FALSE); this->SetSelectionMark(iElement); OK, the selection mark is drawn where it should be, but when I press the down arrow I get the selection not in the next element... I get it over the first element... Could I do anything? Thank you in advance.

    https://www.robotecnik.com freelance robots, PLC and CNC programmer.

    D J 2 Replies Last reply
    0
    • J Joan M

      Hello, INTRODUCTION: I'm using a normal CListCtrl in a dialog based app. When I update/edit a value in the ListCtrl (REPORT MODE) I validate it versus all the other values (they must follow some rules) and if some are not as they should have to be, I modify the variables that are linked to those parameters and then I re-populate ALL the ListCtrl reading those variables... NOTE: I know that this is not the best method... but it works and I have no time to improve it... moreover there are only 8 elements in the ListCtrl. :-O QUESTION: In order not to fool the user I want to be able to place the selection where it was (over the last edited item). The fact is that I can see the selection mark over the desired element, but when I press the down arrow the selection gets placed over the first element. :confused: After the edition I'm using this code now: if (iElement == -1) iElement = this->m_ElementModificatAct.m_iItemActual; this->SetItemState(iElement, LVIS_SELECTED, LVIS_SELECTED | LVIS_FOCUSED); this->EnsureVisible(iElement, FALSE); this->SetSelectionMark(iElement); OK, the selection mark is drawn where it should be, but when I press the down arrow I get the selection not in the next element... I get it over the first element... Could I do anything? Thank you in advance.

      D Offline
      D Offline
      DRHuff
      wrote on last edited by
      #2

      Funny I just solved this after posting a similar question. change this->SetItemState(iElement, LVIS_SELECTED, LVIS_SELECTED | LVIS_FOCUSED); to this->SetItemState(iElement, LVIS_SELECTED**| LVIS_FOCUSED**, LVIS_SELECTED | LVIS_FOCUSED); Dave Huff Igor would you give me a hand with the bags? Certainly - you take the blonde and I'll take the one in the turban!

      J 1 Reply Last reply
      0
      • D DRHuff

        Funny I just solved this after posting a similar question. change this->SetItemState(iElement, LVIS_SELECTED, LVIS_SELECTED | LVIS_FOCUSED); to this->SetItemState(iElement, LVIS_SELECTED**| LVIS_FOCUSED**, LVIS_SELECTED | LVIS_FOCUSED); Dave Huff Igor would you give me a hand with the bags? Certainly - you take the blonde and I'll take the one in the turban!

        J Offline
        J Offline
        Joan M
        wrote on last edited by
        #3

        Works great, thank you!

        https://www.robotecnik.com freelance robots, PLC and CNC programmer.

        1 Reply Last reply
        0
        • J Joan M

          Hello, INTRODUCTION: I'm using a normal CListCtrl in a dialog based app. When I update/edit a value in the ListCtrl (REPORT MODE) I validate it versus all the other values (they must follow some rules) and if some are not as they should have to be, I modify the variables that are linked to those parameters and then I re-populate ALL the ListCtrl reading those variables... NOTE: I know that this is not the best method... but it works and I have no time to improve it... moreover there are only 8 elements in the ListCtrl. :-O QUESTION: In order not to fool the user I want to be able to place the selection where it was (over the last edited item). The fact is that I can see the selection mark over the desired element, but when I press the down arrow the selection gets placed over the first element. :confused: After the edition I'm using this code now: if (iElement == -1) iElement = this->m_ElementModificatAct.m_iItemActual; this->SetItemState(iElement, LVIS_SELECTED, LVIS_SELECTED | LVIS_FOCUSED); this->EnsureVisible(iElement, FALSE); this->SetSelectionMark(iElement); OK, the selection mark is drawn where it should be, but when I press the down arrow I get the selection not in the next element... I get it over the first element... Could I do anything? Thank you in advance.

          J Offline
          J Offline
          Jean Marc Molina
          wrote on last edited by
          #4

          Do you think I can use that trick in order for my list control not to deselect all items one it loses the focus ? When I press a button it deselects all items from the list... I have to select them again... JM Earth > Europe > France > Lyon

          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