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. Change text of header of listCtrl

Change text of header of listCtrl

Scheduled Pinned Locked Moved C / C++ / MFC
13 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.
  • E ensger

    Hallo, Does anyone here know an easy way to change the text of the header of a listCtrl. Till now, I delete all columns and insert them with the new text again. But I think, there should be an easier way:) Thanks, Gerhard

    N Offline
    N Offline
    Nibu babu thomas
    wrote on last edited by
    #2

    ensger wrote:

    Does anyone here know an easy way to change the text of the header of a listCtrl.

    Use SetColumn. An Eg:

    LVCOLUMN lvCol = { 0 };
    lvCol.mask = LVCF_TEXT;
    lvCol.pszText = _T( "Nibu babu thomas" );

    // Change caption of first column
    SetColumn( 0, &lvCol );


    Nibu thomas A Developer Programming tips[^]  My site[^]

    E M 3 Replies Last reply
    0
    • N Nibu babu thomas

      ensger wrote:

      Does anyone here know an easy way to change the text of the header of a listCtrl.

      Use SetColumn. An Eg:

      LVCOLUMN lvCol = { 0 };
      lvCol.mask = LVCF_TEXT;
      lvCol.pszText = _T( "Nibu babu thomas" );

      // Change caption of first column
      SetColumn( 0, &lvCol );


      Nibu thomas A Developer Programming tips[^]  My site[^]

      E Offline
      E Offline
      ensger
      wrote on last edited by
      #3

      Thank's a lot. Seems to work fine. Have a nice weekend, Gerhard

      1 Reply Last reply
      0
      • N Nibu babu thomas

        ensger wrote:

        Does anyone here know an easy way to change the text of the header of a listCtrl.

        Use SetColumn. An Eg:

        LVCOLUMN lvCol = { 0 };
        lvCol.mask = LVCF_TEXT;
        lvCol.pszText = _T( "Nibu babu thomas" );

        // Change caption of first column
        SetColumn( 0, &lvCol );


        Nibu thomas A Developer Programming tips[^]  My site[^]

        E Offline
        E Offline
        ensger
        wrote on last edited by
        #4

        Thank's for the example - my text is stored in a CString. And with this it doesn't work (conversion to string doesn't help). But it works with a code like this: char othertext[100]; sprintf(othertext, "%s", text); lvc.pszText = othertext; Am I crazy to do so????:~

        N 1 Reply Last reply
        0
        • E ensger

          Thank's for the example - my text is stored in a CString. And with this it doesn't work (conversion to string doesn't help). But it works with a code like this: char othertext[100]; sprintf(othertext, "%s", text); lvc.pszText = othertext; Am I crazy to do so????:~

          N Offline
          N Offline
          Nibu babu thomas
          wrote on last edited by
          #5

          ensger wrote:

          char othertext[100]; sprintf(othertext, "%s", text); lvc.pszText = othertext;

          ensger wrote:

          Am I crazy to do so????

          Yes!! What about... lvc.pszText = text; Either way text is a string right? Well if you have want to have strings that contain number then it's quite ok...

          sprintf( othertext, "Column number: %d", 1 );
          lvc.pszText = othertext;


          Nibu thomas A Developer Programming tips[^]  My site[^]

          E 1 Reply Last reply
          0
          • N Nibu babu thomas

            ensger wrote:

            char othertext[100]; sprintf(othertext, "%s", text); lvc.pszText = othertext;

            ensger wrote:

            Am I crazy to do so????

            Yes!! What about... lvc.pszText = text; Either way text is a string right? Well if you have want to have strings that contain number then it's quite ok...

            sprintf( othertext, "Column number: %d", 1 );
            lvc.pszText = othertext;


            Nibu thomas A Developer Programming tips[^]  My site[^]

            E Offline
            E Offline
            ensger
            wrote on last edited by
            #6

            :omg::omg: Maybe my part of code was too short:confused: so I send the whole loop LVCOLUMN lvc; CString titel; int i = 3; if (kstkaranz->wdfirst()) do { i++; titel = kstkaranz->wdgetkstnr() + "\n"; titel = titel + gettitel(0, kstkaranz->wdgetdatenart(), kstkaranz->wdgetvon(), kstkaranz->wdgetbis()); listCtrl.GetColumn(i, &lvc); char strbetrag[100]; sprintf(strbetrag, "%s", titel); lvc.pszText = strbetrag; listCtrl.SetColumn(i, &lvc); } while(kstkaranz->wdnext()); where kstkaranz->wdgetkstnr = something like "6984" (number of a cost center) and the result of gettitle is something like " PLAN VALUES 2007-01-01 - 2007-02-28'. The whole result in titel is a CString (with numbers, of course, but handled as CString). Btw, it works fine and as there should be no difference, whatever the CString titel contains, I see no danger. But your posting made me consider ....?? Btw2: if I try "lvc.pszText = titel;" I get an error-message like (I try to translate): Binary operator: no operator defined who accepts a right-sided operator of type 'class CString' X| -- modified at 12:07 Friday 23rd February, 2007

            N 1 Reply Last reply
            0
            • N Nibu babu thomas

              ensger wrote:

              Does anyone here know an easy way to change the text of the header of a listCtrl.

              Use SetColumn. An Eg:

              LVCOLUMN lvCol = { 0 };
              lvCol.mask = LVCF_TEXT;
              lvCol.pszText = _T( "Nibu babu thomas" );

              // Change caption of first column
              SetColumn( 0, &lvCol );


              Nibu thomas A Developer Programming tips[^]  My site[^]

              M Offline
              M Offline
              Mark Salsbery
              wrote on last edited by
              #7

              I tried your code but now all my columns say "Nibu babu thomas" :omg: Just kidding ;P

              "Do you know what it's like to fall in the mud and get kicked... in the head... with an iron boot? Of course you don't, no one does. It never happens. It's a dumb question... skip it."

              E N 2 Replies Last reply
              0
              • M Mark Salsbery

                I tried your code but now all my columns say "Nibu babu thomas" :omg: Just kidding ;P

                "Do you know what it's like to fall in the mud and get kicked... in the head... with an iron boot? Of course you don't, no one does. It never happens. It's a dumb question... skip it."

                E Offline
                E Offline
                ensger
                wrote on last edited by
                #8

                No problem, if I can say "nibu babu thomas - PLAN Values" and son on:laugh: But indead, his answer helped me very much. I don't know, why he said I'm wrong:confused: No problem, it works:-D

                N 1 Reply Last reply
                0
                • E ensger

                  :omg::omg: Maybe my part of code was too short:confused: so I send the whole loop LVCOLUMN lvc; CString titel; int i = 3; if (kstkaranz->wdfirst()) do { i++; titel = kstkaranz->wdgetkstnr() + "\n"; titel = titel + gettitel(0, kstkaranz->wdgetdatenart(), kstkaranz->wdgetvon(), kstkaranz->wdgetbis()); listCtrl.GetColumn(i, &lvc); char strbetrag[100]; sprintf(strbetrag, "%s", titel); lvc.pszText = strbetrag; listCtrl.SetColumn(i, &lvc); } while(kstkaranz->wdnext()); where kstkaranz->wdgetkstnr = something like "6984" (number of a cost center) and the result of gettitle is something like " PLAN VALUES 2007-01-01 - 2007-02-28'. The whole result in titel is a CString (with numbers, of course, but handled as CString). Btw, it works fine and as there should be no difference, whatever the CString titel contains, I see no danger. But your posting made me consider ....?? Btw2: if I try "lvc.pszText = titel;" I get an error-message like (I try to translate): Binary operator: no operator defined who accepts a right-sided operator of type 'class CString' X| -- modified at 12:07 Friday 23rd February, 2007

                  N Offline
                  N Offline
                  Nibu babu thomas
                  wrote on last edited by
                  #9

                  Your code is fine. But your code snippet made me say that. There is no point in sprintfING another string into another string. Since we already have a string it should be fine. You can assign a CString object into lvc.pszText, do this... lvc.pszText = titlel.GetBuffer(0); // Dont' forget to call ReleaseBuffer titlel.ReleaseBuffer();


                  Nibu thomas A Developer Programming tips[^]  My site[^]

                  E 1 Reply Last reply
                  0
                  • E ensger

                    No problem, if I can say "nibu babu thomas - PLAN Values" and son on:laugh: But indead, his answer helped me very much. I don't know, why he said I'm wrong:confused: No problem, it works:-D

                    N Offline
                    N Offline
                    Nibu babu thomas
                    wrote on last edited by
                    #10

                    ensger wrote:

                    I don't know, why he said I'm wrong

                    I said that from your code snippet. Look at the following example... char title1[100]; sprintf( title, "%s", aString ); What's the point in doing this!!!. Since aString is already a string why not directly assign that string in a proper way and also on the long run this could be a performance hit.


                    Nibu thomas A Developer Programming tips[^]  My site[^]

                    1 Reply Last reply
                    0
                    • M Mark Salsbery

                      I tried your code but now all my columns say "Nibu babu thomas" :omg: Just kidding ;P

                      "Do you know what it's like to fall in the mud and get kicked... in the head... with an iron boot? Of course you don't, no one does. It never happens. It's a dumb question... skip it."

                      N Offline
                      N Offline
                      Nibu babu thomas
                      wrote on last edited by
                      #11

                      Mark Salsbery wrote:

                      I tried your code but now all my columns say "Nibu babu thomas"

                      RLY!! ;P;P


                      Nibu thomas A Developer Programming tips[^]  My site[^]

                      1 Reply Last reply
                      0
                      • N Nibu babu thomas

                        Your code is fine. But your code snippet made me say that. There is no point in sprintfING another string into another string. Since we already have a string it should be fine. You can assign a CString object into lvc.pszText, do this... lvc.pszText = titlel.GetBuffer(0); // Dont' forget to call ReleaseBuffer titlel.ReleaseBuffer();


                        Nibu thomas A Developer Programming tips[^]  My site[^]

                        E Offline
                        E Offline
                        ensger
                        wrote on last edited by
                        #12

                        Hey, this seems to become a fine weekend. I'm just having breakfase (it's 8:00 here), want to read some newspapers in the internet - and the first when I look on my monitor is your message. Of course I tried suddenly and it works! Btw - with ' 'why I'm wrong ' I wanted to say 'why I made something wrong in my code'. My english:-O So, many thanks and have a nice weekend too

                        N 1 Reply Last reply
                        0
                        • E ensger

                          Hey, this seems to become a fine weekend. I'm just having breakfase (it's 8:00 here), want to read some newspapers in the internet - and the first when I look on my monitor is your message. Of course I tried suddenly and it works! Btw - with ' 'why I'm wrong ' I wanted to say 'why I made something wrong in my code'. My english:-O So, many thanks and have a nice weekend too

                          N Offline
                          N Offline
                          Nibu babu thomas
                          wrote on last edited by
                          #13

                          ensger wrote:

                          Btw - with ' 'why I'm wrong '

                          The reason is you could have used "title" directly instead of trasferring it into another string. Does such a copy satisfy any purpose. None AFAIK. It will be a performance hit. It's redundant that's why I said you are wrong. :)


                          Nibu thomas A Developer Programming tips[^]  My site[^]

                          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