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. List Control

List Control

Scheduled Pinned Locked Moved C / C++ / MFC
algorithmshelpquestionworkspace
10 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.
  • A Offline
    A Offline
    aman2006
    wrote on last edited by
    #1

    Hi In one column of List Control i want to show the image but not the values, but with my code(pasted below) it is showing both the image and values. Can any body help me how can i achieve this.But i need to associate the values also because i am doing sorting also on that column //Set up Record Status Holder = pRecordSet->GetCollect("RecordStatus"); status = Holder.iVal; temp.Format("%d",status); m_RecordList->SetItemText(iNew,5,temp); // setup record status lvI.mask=LVIF_IMAGE ; lvI.iItem= iNew; lvI.iSubItem=5; if(status == eCIT_STATUS_COMPLETE) lvI.iImage = 1; else if(status == eCIT_STATUS_VOID) lvI.iImage = 3; else lvI.iImage = 0; m_RecordList->SetItem(&lvI); Thanks Shailesh

    D 1 Reply Last reply
    0
    • A aman2006

      Hi In one column of List Control i want to show the image but not the values, but with my code(pasted below) it is showing both the image and values. Can any body help me how can i achieve this.But i need to associate the values also because i am doing sorting also on that column //Set up Record Status Holder = pRecordSet->GetCollect("RecordStatus"); status = Holder.iVal; temp.Format("%d",status); m_RecordList->SetItemText(iNew,5,temp); // setup record status lvI.mask=LVIF_IMAGE ; lvI.iItem= iNew; lvI.iSubItem=5; if(status == eCIT_STATUS_COMPLETE) lvI.iImage = 1; else if(status == eCIT_STATUS_VOID) lvI.iImage = 3; else lvI.iImage = 0; m_RecordList->SetItem(&lvI); Thanks Shailesh

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

      aman2006 wrote: i want to show the image but not the values Isn't the call to SetItemText() what's showing the value?


      "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

      A 1 Reply Last reply
      0
      • D David Crow

        aman2006 wrote: i want to show the image but not the values Isn't the call to SetItemText() what's showing the value?


        "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

        A Offline
        A Offline
        aman2006
        wrote on last edited by
        #3

        SetItemText() is showing the value but how can i associate a value with the image so that i can sort by clicking on header. But it is showing both values and Image. Thanks shailesh

        D 1 Reply Last reply
        0
        • A aman2006

          SetItemText() is showing the value but how can i associate a value with the image so that i can sort by clicking on header. But it is showing both values and Image. Thanks shailesh

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

          aman2006 wrote: how can i associate a value with the image... Call SetItemData().


          "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

          A 1 Reply Last reply
          0
          • D David Crow

            aman2006 wrote: how can i associate a value with the image... Call SetItemData().


            "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

            A Offline
            A Offline
            aman2006
            wrote on last edited by
            #5

            Hey this is the situation now but it is not sorting when i click on the header column. //Set up Record Status Holder = pRecordSet->GetCollect("RecordStatus"); status = Holder.iVal; m_RecordList->SetItemData(iNew,status); // setup record status lvI.mask=LVIF_IMAGE ; lvI.iItem= iNew; lvI.iSubItem=5; if(status == eCIT_STATUS_COMPLETE) lvI.iImage = 1; else if(status == eCIT_STATUS_VOID) lvI.iImage = 3; else lvI.iImage = 0; m_RecordList->SetItem(&lvI); Any Suggestion Thanks

            D 1 Reply Last reply
            0
            • A aman2006

              Hey this is the situation now but it is not sorting when i click on the header column. //Set up Record Status Holder = pRecordSet->GetCollect("RecordStatus"); status = Holder.iVal; m_RecordList->SetItemData(iNew,status); // setup record status lvI.mask=LVIF_IMAGE ; lvI.iItem= iNew; lvI.iSubItem=5; if(status == eCIT_STATUS_COMPLETE) lvI.iImage = 1; else if(status == eCIT_STATUS_VOID) lvI.iImage = 3; else lvI.iImage = 0; m_RecordList->SetItem(&lvI); Any Suggestion Thanks

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

              aman2006 wrote: ...it is not sorting when i click on the header column And what does the handler code for that look like?


              "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

              A 1 Reply Last reply
              0
              • D David Crow

                aman2006 wrote: ...it is not sorting when i click on the header column And what does the handler code for that look like?


                "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

                A Offline
                A Offline
                aman2006
                wrote on last edited by
                #7

                David this the full code while(!pRecordSet->EndOfFile) { // Insert the first item lvI.mask = LVIF_TEXT| LVIF_PARAM | LVIF_STATE; lvI.state = 0; lvI.stateMask = 0; lvI.iItem = counter; lvI.iSubItem = 0; Holder = pRecordSet->GetCollect("CitationID"); if(Holder.vt!=VT_NULL) { temp = (char*)_bstr_t(Holder); lvI.pszText = (LPTSTR)(LPCTSTR)(temp); } else lvI.pszText = _T(""); //lvI.pszText = _T(""); lvI.lParam = counter; int iNew = m_RecordList->InsertItem(&lvI); Holder = pRecordSet->GetCollect("CitationNo"); if(Holder.vt!=VT_NULL) { temp = (char*)_bstr_t(Holder); lvI.pszText = (LPTSTR)(LPCTSTR)(temp); } else lvI.pszText = _T(""); m_RecordList->SetItemText(iNew,1,temp); //Citation date Holder = pRecordSet->GetCollect("CitationDate"); if(Holder.vt!=VT_NULL) { temp = (char*)_bstr_t(Holder); lvI.pszText = (LPTSTR)(LPCTSTR)(temp); } else lvI.pszText = _T(""); m_RecordList->SetItemText(iNew,2,temp); //Citation Time Holder = pRecordSet->GetCollect("CitationTime"); if(Holder.vt!=VT_NULL) { temp = (char*)_bstr_t(Holder); lvI.pszText = (LPTSTR)(LPCTSTR)(temp); } else lvI.pszText = _T(""); m_RecordList->SetItemText(iNew,3,temp); //Subject First Name strFName.Empty(); Holder = pRecordSet->GetCollect("FirstName"); if(Holder.vt!=VT_NULL) strFName = (char*)_bstr_t(Holder); else strFName = _T(""); //Subject Last Name Holder = pRecordSet->GetCollect("LastName"); if(Holder.vt!=VT_NULL) { temp = (char*)_bstr_t(Holder); // lvI.pszText = (LPTSTR)(LPCTSTR)(temp); } else temp = _T(""); strFName += _T(" ") + temp; lvI.pszText = (LPTSTR)(LPCTSTR)(strFName); m_RecordList->SetItemText(iNew,4,strFName); //Set up Record Status Holder = pRecordSet->GetCollect("RecordStatus"); status = Holder.iVal; m_RecordList->SetItemData(iNew,status); // setup record status lvI.mask=LVIF_IMAGE; lvI.iItem= iNew; lvI.iSubItem=5; if(status == eCIT_STATUS_COMPLETE) lvI.iImage = 1; else if(status == eCIT_STATUS_VOID) lvI.iImage = 3; else lvI.iImage = 0; m_RecordList->SetItem(&lvI); //Set up Sync Status Holder = pRecordSet->GetCollect("IsSynchronized"); status = Holder.iVal; temp.Format("%

                D 1 Reply Last reply
                0
                • A aman2006

                  David this the full code while(!pRecordSet->EndOfFile) { // Insert the first item lvI.mask = LVIF_TEXT| LVIF_PARAM | LVIF_STATE; lvI.state = 0; lvI.stateMask = 0; lvI.iItem = counter; lvI.iSubItem = 0; Holder = pRecordSet->GetCollect("CitationID"); if(Holder.vt!=VT_NULL) { temp = (char*)_bstr_t(Holder); lvI.pszText = (LPTSTR)(LPCTSTR)(temp); } else lvI.pszText = _T(""); //lvI.pszText = _T(""); lvI.lParam = counter; int iNew = m_RecordList->InsertItem(&lvI); Holder = pRecordSet->GetCollect("CitationNo"); if(Holder.vt!=VT_NULL) { temp = (char*)_bstr_t(Holder); lvI.pszText = (LPTSTR)(LPCTSTR)(temp); } else lvI.pszText = _T(""); m_RecordList->SetItemText(iNew,1,temp); //Citation date Holder = pRecordSet->GetCollect("CitationDate"); if(Holder.vt!=VT_NULL) { temp = (char*)_bstr_t(Holder); lvI.pszText = (LPTSTR)(LPCTSTR)(temp); } else lvI.pszText = _T(""); m_RecordList->SetItemText(iNew,2,temp); //Citation Time Holder = pRecordSet->GetCollect("CitationTime"); if(Holder.vt!=VT_NULL) { temp = (char*)_bstr_t(Holder); lvI.pszText = (LPTSTR)(LPCTSTR)(temp); } else lvI.pszText = _T(""); m_RecordList->SetItemText(iNew,3,temp); //Subject First Name strFName.Empty(); Holder = pRecordSet->GetCollect("FirstName"); if(Holder.vt!=VT_NULL) strFName = (char*)_bstr_t(Holder); else strFName = _T(""); //Subject Last Name Holder = pRecordSet->GetCollect("LastName"); if(Holder.vt!=VT_NULL) { temp = (char*)_bstr_t(Holder); // lvI.pszText = (LPTSTR)(LPCTSTR)(temp); } else temp = _T(""); strFName += _T(" ") + temp; lvI.pszText = (LPTSTR)(LPCTSTR)(strFName); m_RecordList->SetItemText(iNew,4,strFName); //Set up Record Status Holder = pRecordSet->GetCollect("RecordStatus"); status = Holder.iVal; m_RecordList->SetItemData(iNew,status); // setup record status lvI.mask=LVIF_IMAGE; lvI.iItem= iNew; lvI.iSubItem=5; if(status == eCIT_STATUS_COMPLETE) lvI.iImage = 1; else if(status == eCIT_STATUS_VOID) lvI.iImage = 3; else lvI.iImage = 0; m_RecordList->SetItem(&lvI); //Set up Sync Status Holder = pRecordSet->GetCollect("IsSynchronized"); status = Holder.iVal; temp.Format("%

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

                  This is the code that populates the list control. I wanted to see the code that handles the clicking of the column heading, and the sorting-compare routine.


                  "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

                  A 1 Reply Last reply
                  0
                  • D David Crow

                    This is the code that populates the list control. I wanted to see the code that handles the clicking of the column heading, and the sorting-compare routine.


                    "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

                    A Offline
                    A Offline
                    aman2006
                    wrote on last edited by
                    #9

                    Here u go: typedef struct _tagSORTDATA { INT isortSubItem; CListCtrl *m_pointer; INT iUPDOWN; BOOL StringComp; } SORTDATA; enum{ eSORT_UP = 1, eSORT_DOWN }; void CEditForm::OnColumnclickHistoryList(NMHDR* pNMHDR, LRESULT* pResult) { NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; static WORD nSort; SORTDATA sortData; m_RecordList =(CListCtrl*)GetDlgItem(IDC_HISTORY_LIST); if(nSort == eSORT_UP) nSort = eSORT_DOWN; else nSort = eSORT_UP; sortData.isortSubItem = pNMListView->iSubItem; sortData.iUPDOWN = nSort; sortData.m_pointer = (CListCtrl*)m_RecordList; sortData.StringComp = TRUE; if(m_RecordList->SortItems(ListViewCompProc, (DWORD)(LPARAM)&sortData) != TRUE) AfxMessageBox(_T("Error")); *pResult = 0; } int CALLBACK CEditForm::ListViewCompProc(LPARAM lp1, LPARAM lp2, LPARAM lp3) { static LVFINDINFO lvf; static INT nItem1, nItem2; CString buf1, buf2; SORTDATA *lpsd; lpsd = (SORTDATA *)lp3; CListCtrl *m_RecordList = (CListCtrl*)lpsd->m_pointer; lvf.flags = LVFI_PARAM; lvf.lParam = lp1; // nItem1 = ListView_FindItem(lpsd->hwndList, -1, &lvf); nItem1 = m_RecordList->FindItem(&lvf); lvf.lParam = lp2; //nItem2 = ListView_FindItem(lpsd->hwndList, -1, &lvf); nItem2 = m_RecordList->FindItem(&lvf); //ListView_GetItemText(lpsd->hwndList, nItem1, lpsd->isortSubItem, buf1, sizeof(buf1)); buf1 = m_RecordList->GetItemText(nItem1,lpsd->isortSubItem); //ListView_GetItemText(lpsd->hwndList, nItem2, lpsd->isortSubItem, buf2, sizeof(buf2)); buf2 = m_RecordList->GetItemText(nItem2,lpsd->isortSubItem); if (lpsd->isortSubItem != 9) { // string comparision if (lpsd->iUPDOWN == eSORT_UP) { return(buf1.Compare(buf2)); } else { return(buf1.Compare(buf2) * -1); } } else { // digit comparision if (lpsd->iUPDOWN == eSORT_UP) { if (_ttoi(buf1) > _ttoi(buf2)) return 1; else if (_ttoi(buf1) == _ttoi(buf2)) return 0; else return -1; } else { if (_ttoi(buf1) > _ttoi(buf2)) return -1; else if (_ttoi(buf1) == _ttoi(buf2)) return 0; else return 1; } } return 0; }

                    D 1 Reply Last reply
                    0
                    • A aman2006

                      Here u go: typedef struct _tagSORTDATA { INT isortSubItem; CListCtrl *m_pointer; INT iUPDOWN; BOOL StringComp; } SORTDATA; enum{ eSORT_UP = 1, eSORT_DOWN }; void CEditForm::OnColumnclickHistoryList(NMHDR* pNMHDR, LRESULT* pResult) { NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; static WORD nSort; SORTDATA sortData; m_RecordList =(CListCtrl*)GetDlgItem(IDC_HISTORY_LIST); if(nSort == eSORT_UP) nSort = eSORT_DOWN; else nSort = eSORT_UP; sortData.isortSubItem = pNMListView->iSubItem; sortData.iUPDOWN = nSort; sortData.m_pointer = (CListCtrl*)m_RecordList; sortData.StringComp = TRUE; if(m_RecordList->SortItems(ListViewCompProc, (DWORD)(LPARAM)&sortData) != TRUE) AfxMessageBox(_T("Error")); *pResult = 0; } int CALLBACK CEditForm::ListViewCompProc(LPARAM lp1, LPARAM lp2, LPARAM lp3) { static LVFINDINFO lvf; static INT nItem1, nItem2; CString buf1, buf2; SORTDATA *lpsd; lpsd = (SORTDATA *)lp3; CListCtrl *m_RecordList = (CListCtrl*)lpsd->m_pointer; lvf.flags = LVFI_PARAM; lvf.lParam = lp1; // nItem1 = ListView_FindItem(lpsd->hwndList, -1, &lvf); nItem1 = m_RecordList->FindItem(&lvf); lvf.lParam = lp2; //nItem2 = ListView_FindItem(lpsd->hwndList, -1, &lvf); nItem2 = m_RecordList->FindItem(&lvf); //ListView_GetItemText(lpsd->hwndList, nItem1, lpsd->isortSubItem, buf1, sizeof(buf1)); buf1 = m_RecordList->GetItemText(nItem1,lpsd->isortSubItem); //ListView_GetItemText(lpsd->hwndList, nItem2, lpsd->isortSubItem, buf2, sizeof(buf2)); buf2 = m_RecordList->GetItemText(nItem2,lpsd->isortSubItem); if (lpsd->isortSubItem != 9) { // string comparision if (lpsd->iUPDOWN == eSORT_UP) { return(buf1.Compare(buf2)); } else { return(buf1.Compare(buf2) * -1); } } else { // digit comparision if (lpsd->iUPDOWN == eSORT_UP) { if (_ttoi(buf1) > _ttoi(buf2)) return 1; else if (_ttoi(buf1) == _ttoi(buf2)) return 0; else return -1; } else { if (_ttoi(buf1) > _ttoi(buf2)) return -1; else if (_ttoi(buf1) == _ttoi(buf2)) return 0; else return 1; } } return 0; }

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

                      In the ListViewCompProc() routine, don't call FindItem() or GetItemText(). Use the lp1 and lp2 parameters instead. See MSDN article Q250614.


                      "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

                      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