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. MFC CListCtrl how to Display SubItem text with tabulator ?

MFC CListCtrl how to Display SubItem text with tabulator ?

Scheduled Pinned Locked Moved C / C++ / MFC
c++helptutorialquestion
9 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.
  • M Offline
    M Offline
    Member 8534035
    wrote on last edited by
    #1

    Hi all, I am inserting text to CListCtrl Items with function SetItemText(). The text contains '\t'. I would need to display the text of the subitems with expanded tabulators. Is there a way? I cannot find any hints about this issue. Many Thanks

    L D 2 Replies Last reply
    0
    • M Member 8534035

      Hi all, I am inserting text to CListCtrl Items with function SetItemText(). The text contains '\t'. I would need to display the text of the subitems with expanded tabulators. Is there a way? I cannot find any hints about this issue. Many Thanks

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You need to expand the tabs yourself before adding the strings to the control.

      M 1 Reply Last reply
      0
      • L Lost User

        You need to expand the tabs yourself before adding the strings to the control.

        M Offline
        M Offline
        Member 8534035
        wrote on last edited by
        #3

        you propose to replace with number of tabs? it's much effort, because I need to loop over the text and replace by different number of tabs (depending on position). further this works only for fix size fonts.

        L 1 Reply Last reply
        0
        • M Member 8534035

          you propose to replace with number of tabs? it's much effort, because I need to loop over the text and replace by different number of tabs (depending on position). further this works only for fix size fonts.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Well the issue is quite simple: if the control does not expand them for you, then you will need to do it yourself. You can use the GetTextExtentPoint32 function[^] to calculate the average size of the characters, and use that information to calculate the width of the tabs.

          M 1 Reply Last reply
          0
          • L Lost User

            Well the issue is quite simple: if the control does not expand them for you, then you will need to do it yourself. You can use the GetTextExtentPoint32 function[^] to calculate the average size of the characters, and use that information to calculate the width of the tabs.

            M Offline
            M Offline
            Member 8534035
            wrote on last edited by
            #5

            hmm, maybe I do not understand this approach completely! I could calculate the text size and tab position. but when replacing the tab character with a number of blanks, I will not get an accurate tab position. it will looks quite crude over several lines. further I will have additional issues with the blanks, when I want do make in place edititing. Is there any possibility to draw the text of an subitem by myself? e.g. if I would catch a notification message that an subitem needs to be drawn, that I call a function like CDC::TabbedTextOut() ? Thanks again!

            L 1 Reply Last reply
            0
            • M Member 8534035

              hmm, maybe I do not understand this approach completely! I could calculate the text size and tab position. but when replacing the tab character with a number of blanks, I will not get an accurate tab position. it will looks quite crude over several lines. further I will have additional issues with the blanks, when I want do make in place edititing. Is there any possibility to draw the text of an subitem by myself? e.g. if I would catch a notification message that an subitem needs to be drawn, that I call a function like CDC::TabbedTextOut() ? Thanks again!

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              You are right, it cannot be exact in such a control. However you may be able to do better by drawing the text via a callback: see https://msdn.microsoft.com/en-gb/library/9w88k8yh.aspx[^].

              1 Reply Last reply
              0
              • M Member 8534035

                Hi all, I am inserting text to CListCtrl Items with function SetItemText(). The text contains '\t'. I would need to display the text of the subitems with expanded tabulators. Is there a way? I cannot find any hints about this issue. Many Thanks

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

                Member 8534035 wrote:

                I am inserting text to CListCtrl Items with function SetItemText().

                What does the call to SetItemText() look like?

                Member 8534035 wrote:

                The text contains 't\'.

                What is so special about the letter t followed by a backslash?

                Member 8534035 wrote:

                I would need to display the text of the subitems with expanded tabulators.

                What in the world does this mean?

                "One man's wage rise is another man's price increase." - Harold Wilson

                "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                M 1 Reply Last reply
                0
                • D David Crow

                  Member 8534035 wrote:

                  I am inserting text to CListCtrl Items with function SetItemText().

                  What does the call to SetItemText() look like?

                  Member 8534035 wrote:

                  The text contains 't\'.

                  What is so special about the letter t followed by a backslash?

                  Member 8534035 wrote:

                  I would need to display the text of the subitems with expanded tabulators.

                  What in the world does this mean?

                  "One man's wage rise is another man's price increase." - Harold Wilson

                  "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                  "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                  M Offline
                  M Offline
                  Member 8534035
                  wrote on last edited by
                  #8

                  sorry, I was talking about '\t', the ASCII sign for tabulator. If I assign a text with SetItemText() to a CListCtrl item, the tabulator is ignored completely. e.g. "label:\tsome text which should begin at next tabulator position" The CListCtrl is not viewing any spacing for the tabulator.

                  D 1 Reply Last reply
                  0
                  • M Member 8534035

                    sorry, I was talking about '\t', the ASCII sign for tabulator. If I assign a text with SetItemText() to a CListCtrl item, the tabulator is ignored completely. e.g. "label:\tsome text which should begin at next tabulator position" The CListCtrl is not viewing any spacing for the tabulator.

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

                    Member 8534035 wrote:

                    ...the tabulator is ignored completely.

                    Of course, since it was not meant to handle it as a special case. One solution would be to call AfxExtractSubString() to break your source string up into its individual tokens. Then you could call InsertItem() to insert an item in the list control, followed by SetItemText() to set the text of subitems.

                    "One man's wage rise is another man's price increase." - Harold Wilson

                    "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                    "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                    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