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. Listcontrol problem

Listcontrol problem

Scheduled Pinned Locked Moved C / C++ / MFC
databasedesigndata-structureshelp
2 Posts 2 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
    JHAKAS
    wrote on last edited by
    #1

    listCtrl problem: Hello I am inserting some item to list control from database. Say items are stored in database as following: A1, B1, C1, A2, B2, C2,A3,B3,C3 ------ line 1 My list control is in ascending sort order, so it displays the design as alphabetically ascending order: A1, A2, A3, B1, B2, B3, C1, C2, C3 ------ line 2 Now in list box i am selecting B1,B2,B3 and using following code: POSITION pos = m_DesignList.GetFirstSelectedItemPosition(); // Get all the item in the listview selected 's Design ID // and assign it to the IDArray in the following loop if (pos == NULL) TRACE0("No items were selected!\n"); else while (pos) { int nItem = m_DesignList.GetNextSelectedItem(pos); if(D_EXPORT == m_ModeFlag ) // EXPORT mode { // indexArr is array filled in function onInitDialog. So it contains index value as shown in line 1 IDArray[incr++] = indexArr[nItem]; -- line 3 } m_indexCount ++; // Increase the counter of number of designs selected } Line 3- is the main root of problem. When i select say B1,B2,B3 from the list , so as there index in the list are 3,4,5 (0 based), but actually in the recordset they are 1,4,7 instead Note: I have to keep the Listcontrol items in sorted manner. Leave your mark wherever you go

    M 1 Reply Last reply
    0
    • J JHAKAS

      listCtrl problem: Hello I am inserting some item to list control from database. Say items are stored in database as following: A1, B1, C1, A2, B2, C2,A3,B3,C3 ------ line 1 My list control is in ascending sort order, so it displays the design as alphabetically ascending order: A1, A2, A3, B1, B2, B3, C1, C2, C3 ------ line 2 Now in list box i am selecting B1,B2,B3 and using following code: POSITION pos = m_DesignList.GetFirstSelectedItemPosition(); // Get all the item in the listview selected 's Design ID // and assign it to the IDArray in the following loop if (pos == NULL) TRACE0("No items were selected!\n"); else while (pos) { int nItem = m_DesignList.GetNextSelectedItem(pos); if(D_EXPORT == m_ModeFlag ) // EXPORT mode { // indexArr is array filled in function onInitDialog. So it contains index value as shown in line 1 IDArray[incr++] = indexArr[nItem]; -- line 3 } m_indexCount ++; // Increase the counter of number of designs selected } Line 3- is the main root of problem. When i select say B1,B2,B3 from the list , so as there index in the list are 3,4,5 (0 based), but actually in the recordset they are 1,4,7 instead Note: I have to keep the Listcontrol items in sorted manner. Leave your mark wherever you go

      M Offline
      M Offline
      Michael P Butler
      wrote on last edited by
      #2

      The usual way to resolve this is to store the correct index / or a pointer to the data using SetItemData and GetItemData methods of CListCtrl. Have a look on MSDN for those two functions. There should be a good example. Michael CP Blog [^]

      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