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. CListCtrl improving

CListCtrl improving

Scheduled Pinned Locked Moved C / C++ / MFC
questiontutorial
9 Posts 4 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
    JensB
    wrote on last edited by
    #1

    Hi. I've subclassed the CListCtrl. You can edit a subitem, and type some text into it. But if you resize the column (making it larger for example) then the editbox need to be redrawn to fill the whole (new) column space. Mine stays the same, how can i achieve this? Greetings Jens

    T S 2 Replies Last reply
    0
    • J JensB

      Hi. I've subclassed the CListCtrl. You can edit a subitem, and type some text into it. But if you resize the column (making it larger for example) then the editbox need to be redrawn to fill the whole (new) column space. Mine stays the same, how can i achieve this? Greetings Jens

      T Offline
      T Offline
      tomiczek
      wrote on last edited by
      #2

      derive a Class from CEdit and overwite in ON_WM_WINDOWPOSCHANGING... add a Variable for the Size of the Subitem e.g RECT m_Position; In the Beginlabeledit-Handler of your ListCtrl SubClass the ListCtrl's EditCtrl with your derived class like this: OnBeginlabeledit(NMHDR* pNMHDR, LRESULT* pResult) { // Pseudo Code CREct Rect; GetSubItemRect(nItem, nSubItem, LVIR_LABEL, Rect); HWND hWnd=(HWND)SendMessage(LVM_GETEDITCONTROL); m_DerivedEdit.SubclassWindow(hWnd); m_DerivedEdit.SetPosition(Rect); } with SetPosition you should set the RECT m_Position of your derived Edit class... in the ON_WM_WINDOWPOSCHANGING - Handler you can adjust the Position of the ListCtrl's EditCtrl as follows: CDerivedEdit::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos) { lpwndpos->x = m_Position.left; lpwndpos->y = m_Position.top; lpwndpos->cx = m_Position.Width(); lpwndpos->cy = m_Position.Height(); } Hope this helps...

      J 1 Reply Last reply
      0
      • T tomiczek

        derive a Class from CEdit and overwite in ON_WM_WINDOWPOSCHANGING... add a Variable for the Size of the Subitem e.g RECT m_Position; In the Beginlabeledit-Handler of your ListCtrl SubClass the ListCtrl's EditCtrl with your derived class like this: OnBeginlabeledit(NMHDR* pNMHDR, LRESULT* pResult) { // Pseudo Code CREct Rect; GetSubItemRect(nItem, nSubItem, LVIR_LABEL, Rect); HWND hWnd=(HWND)SendMessage(LVM_GETEDITCONTROL); m_DerivedEdit.SubclassWindow(hWnd); m_DerivedEdit.SetPosition(Rect); } with SetPosition you should set the RECT m_Position of your derived Edit class... in the ON_WM_WINDOWPOSCHANGING - Handler you can adjust the Position of the ListCtrl's EditCtrl as follows: CDerivedEdit::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos) { lpwndpos->x = m_Position.left; lpwndpos->y = m_Position.top; lpwndpos->cx = m_Position.Width(); lpwndpos->cy = m_Position.Height(); } Hope this helps...

        J Offline
        J Offline
        JensB
        wrote on last edited by
        #3

        It should help but void CMyEdit::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos) { RECT temp= GetPosition(); lpwndpos->x = temp.left; lpwndpos->y = temp.top; lpwndpos->cx = temp.Width(); lpwndpos->cy = temp.Right(); SetPosition(temp); } m_position is private, that's why i need a temp one. I get an error on the temp.Width() and temp.Right(): error C2039: 'Width' : is not a member of 'tagRECT' error C2039: 'Right' : is not a member of 'tagRECT' which is kinda normal becz RECT is a structure, not a class. How can i fix it? (when to use RECT, and when to use CRect?)

        A 1 Reply Last reply
        0
        • J JensB

          It should help but void CMyEdit::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos) { RECT temp= GetPosition(); lpwndpos->x = temp.left; lpwndpos->y = temp.top; lpwndpos->cx = temp.Width(); lpwndpos->cy = temp.Right(); SetPosition(temp); } m_position is private, that's why i need a temp one. I get an error on the temp.Width() and temp.Right(): error C2039: 'Width' : is not a member of 'tagRECT' error C2039: 'Right' : is not a member of 'tagRECT' which is kinda normal becz RECT is a structure, not a class. How can i fix it? (when to use RECT, and when to use CRect?)

          A Offline
          A Offline
          Alin Negru
          wrote on last edited by
          #4

          JensB wrote: void CMyEdit::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos) { CRect temp= GetPosition();// use CRect instead of RECT and it will work lpwndpos->x = temp.left; lpwndpos->y = temp.top; lpwndpos->cx = temp.Width(); lpwndpos->cy = temp.Right(); SetPosition(temp); }

          J 1 Reply Last reply
          0
          • J JensB

            Hi. I've subclassed the CListCtrl. You can edit a subitem, and type some text into it. But if you resize the column (making it larger for example) then the editbox need to be redrawn to fill the whole (new) column space. Mine stays the same, how can i achieve this? Greetings Jens

            S Offline
            S Offline
            sulaxan
            wrote on last edited by
            #5

            hello..... hey do u know how to disable the user control from resizing the columns of the list control...... plz reply if u have any idea abt it yaar thanks in advance Adi

            J 1 Reply Last reply
            0
            • A Alin Negru

              JensB wrote: void CMyEdit::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos) { CRect temp= GetPosition();// use CRect instead of RECT and it will work lpwndpos->x = temp.left; lpwndpos->y = temp.top; lpwndpos->cx = temp.Width(); lpwndpos->cy = temp.Right(); SetPosition(temp); }

              J Offline
              J Offline
              JensB
              wrote on last edited by
              #6

              ok, i've changed the data member to CRect instead of RECT structure but it still doesn't work. I'll paste what i have done: in the derived class of CListCtrl CEdit* CMyListCtrl::EditSubLabel( int nItem, int nCol ) { ... CRect rect; //set rect .. CEdit *pEdit = new CInPlaceEdit(nItem, nCol, GetItemText(nItem, nCol), GetColumnType(nCol), rect); pEdit->Create...... void CInPlaceEdit::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos) { //CEdit::OnWindowPosChanging(lpwndpos); //Positie veranderde! CRect temp; temp = GetPosition(); lpwndpos->x = temp.left; lpwndpos->y = temp.top; lpwndpos->cx = temp.Width(); lpwndpos->cy = temp.Height(); SetPosition(temp); //positie zetten //CEdit::OnWindowPosChanging(lpwndpos); } i don't see any difference, if i move the column more larger (editbox isn't made langer). what am i still doing wrong? :(

              T 1 Reply Last reply
              0
              • S sulaxan

                hello..... hey do u know how to disable the user control from resizing the columns of the list control...... plz reply if u have any idea abt it yaar thanks in advance Adi

                J Offline
                J Offline
                JensB
                wrote on last edited by
                #7

                yes, check: http://www.codeguru.com/listview/no\_col\_resize.shtml http://www.codeguru.com/listview/no\_col\_resize2.shtml here you go :)

                J 1 Reply Last reply
                0
                • J JensB

                  ok, i've changed the data member to CRect instead of RECT structure but it still doesn't work. I'll paste what i have done: in the derived class of CListCtrl CEdit* CMyListCtrl::EditSubLabel( int nItem, int nCol ) { ... CRect rect; //set rect .. CEdit *pEdit = new CInPlaceEdit(nItem, nCol, GetItemText(nItem, nCol), GetColumnType(nCol), rect); pEdit->Create...... void CInPlaceEdit::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos) { //CEdit::OnWindowPosChanging(lpwndpos); //Positie veranderde! CRect temp; temp = GetPosition(); lpwndpos->x = temp.left; lpwndpos->y = temp.top; lpwndpos->cx = temp.Width(); lpwndpos->cy = temp.Height(); SetPosition(temp); //positie zetten //CEdit::OnWindowPosChanging(lpwndpos); } i don't see any difference, if i move the column more larger (editbox isn't made langer). what am i still doing wrong? :(

                  T Offline
                  T Offline
                  tomiczek
                  wrote on last edited by
                  #8

                  change your code To CRect rect; //set rect GetSubItemRect(nItem, nCol, LVIR_LABEL, rect); CEdit *pEdit = new CInPlaceEdit(nItem, nCol, GetItemText(nItem, nCol), GetColumnType(nCol), rect);

                  1 Reply Last reply
                  0
                  • J JensB

                    yes, check: http://www.codeguru.com/listview/no\_col\_resize.shtml http://www.codeguru.com/listview/no\_col\_resize2.shtml here you go :)

                    J Offline
                    J Offline
                    JensB
                    wrote on last edited by
                    #9

                    CRect rect; this.GetSubItemRect(nItem, nCol, LVIR_LABEL, rect); error -> GetSubItemRect' : is not a member of 'CMyListCtrl' (class CMyListCtrl : public CListCtrl) although it is a member .. pff i don't understand it anymore :confused:

                    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