Header line of a ListView

vieuxray -  
 vieuxray -
Good evening everyone, forum good evening,

<config>Windows 10/ Internet Explorer 11.0</Excel 2007-- VBA>

I have seen during my various research on the internet the possibility of coloring the row and/or the text containing the headers of a ListView. Usually, I save tips and tricks, but I forgot this time.

So, I can no longer find this tip.

I am looking for the code to change the color of the row or the text color, whatever can be done.

Thank you all for your help, soon the end of the year 2018, so happy holidays to everyone.

Best regards, Ray

 Public Sub Remplissage() Set Feuil1 = ActiveSheet With ListView1 .Gridlines = True .FullRowSelect = True .FlatScrollBar = True .LabelEdit = lvwManual With .ColumnHeaders Clearlist .Add , , " ( I )", 43, lvwColumnLeft .Add , , "( J )", 43, lvwColumnCenter .Add , , "( K )", 43, lvwColumnCenter .Add , , "( L )", 43, lvwColumnCenter .Add , , "( M )", 43, lvwColumnCenter .Add , , "( N )", 43, lvwColumnCenter .Add , , "( O )", 43, lvwColumnCenter End With End With 

12 answers

  1. vieuxray
     
    Hi f894009,

    Thank you very much for the find; the code I had seen was much shorter, but we still need to know if it was really for the headers, I don’t remember very well.

    Thank you for modifying the code. I will try to adapt it to my program, but still, I didn’t expect such a long code just for the headers.

    I just did a first test, and there are several undeclared variables according to OPTION EXPLICIT. I will try to tidy things up if I can.

    In any case, thanks again for this find.

    Have a good Sunday.

    Best regards, Ray
    0
    1. f894009 Posted messages 17417 Registration date   Status Member Last intervention   1 717
       
      Re,
      but it remains to be seen if it was good for the headers, I don't really remember well.


      No problem, if it's for the other lines, I have what it takes, but only the text color...
      0
  2. vieuxray
     
    Hello f894009,

    Thank you for your response,

    I modified the code you sent me this morning and it crashed Excel; I must have done something wrong.

    So, I deleted the file and I’m going to start over. However, you suggested (No problem, if it's for the other lines, I have what you need, but only the text color), I'm interested, so if you could please integrate all that into the file from this morning, as I would see everything at once.

    Given the time, enjoy your meal and have a great Sunday, and thank you.

    Best regards, Ray
    0
    1. f894009 Posted messages 17417 Registration date   Status Member Last intervention   1 717
       
      Hello,

      integrate all of this into the file from this morning,
      It's already in the file that I modified for you.....I forgot to tell you that................
      The lines of the listview are in red instead of black.
      0
  3. vieuxray
     
    Hello f894009,

    Thank you for the response,

    I have a little issue, I took your file back and did some tests but there is a problem that I couldn't find.
    I didn't modify the file, I launch it, open the USF and click on the button that displays the header in red background and white text and
    the list is displayed in red but as soon as I click on a line to see what happens, Excel crashes and I have to exit using CTRL shift and enter and then end the task.

    You mentioned that the lines of the listview are in red instead of black, instead of what does that mean ???? I didn't understand.

    Thank you for your help, have a good day.

    Best regards, Ray
    0
    1. f894009 Posted messages 17417 Registration date   Status Member Last intervention   1 717
       
      Re,

      ald which means ????: Instead of

      Planting: I forgot to remove code after trying background color lines other than the header

      File ok: https://mon-partage.fr/f/HEzQd4Rq/
      0
  4. vieuxray
     
    Hello f894009,

    Thank you for getting back with the file, unfortunately it doesn't change anything for me, it still crashes as soon as I click the button to display the list in listview1.
    There is something it doesn't like right from the start.

    I haven't touched anything in the code, I promise hehehe

    Enjoy your meal, talk to you later and thanks

    Best regards, Ray
    0
    1. f894009 Posted messages 17417 Registration date   Status Member Last intervention   1 717
       
      Re,

      What a pity!!!
      My mistake, the line color change is not written in this file, I had considered it but didn't do it. I'm modifying the file by commenting out the header color part.


      Modified file: https://mon-partage.fr/f/N8RfiIby/
      0
  5. vieuxray
     
    Re f894009,

    Thank you for the code modification, it's working much better without Excel crashing.

    The rows are coloring nicely, so we could use a different color for each column, which is great, thanks.

    However, can I stop changing the color of the header row???

    See you later
    Best regards, Ray
    0
    1. f894009 Posted messages 17417 Registration date   Status Member Last intervention   1 717
       
      Re,

      Ok, I got a little carried away. I'll correct it

      https://mon-partage.fr/f/WjAmHRWp/
      0
  6. vieuxray
     
    Happy New Year's Eve to you
    Best regards, Ray
    0
  7. vieuxray
     
    Hello f894009,

    I am sending you my best wishes for this new year.

    Thank you for the file return, sorry but I have an issue, I open the file, click on the button, the list displays well, header row in red, text in white.

    Then poof Excel crashes, no other solution than the 3 keys to get out CTRL Shift enter and task manager.

    Have a great first day of 2019, thank you.

    Best regards, Ray
    0
    1. f894009 Posted messages 17417 Registration date   Status Member Last intervention   1 717
       
      Re,

      Header line in red, white text.
      Yes, the color needs to be modified in userform_initialize at the end of the procedure

      Then plouf Excel crashes
      Yes, but I have no problems here!!!

      We should set a breakpoint at the beginning of:
      Private Sub CommandButton1_Click()


      Launch the userform and as soon as the execution stops, press the F8 key to step through the code line by line to see where it crashes.


      Question: which file are you using??
      0
  8. vieuxray
     
    Re,
    for the file, I'm using the one you sent me this morning
    I don't tinker with the file until it works, then I make a backup and modify it, I look at how it works
    and adapt it to my source file.

    I've followed your advice:
    I should set a breakpoint at the beginning of: Private Sub CommandButton1_Click()

    Run the userform and as soon as execution stops, press the F8 key to step through the code line by line to see where it fails.

    As soon as I click F8, it fails there, and I no longer have access to the faulty code.

    Have a good day

    Best regards, Ray
    0
    1. f894009 Posted messages 17417 Registration date   Status Member Last intervention   1 717
       
      Re,
      Well!!! I can't see what it could be!!
      However, there's something that doesn't add up; you wrote that the list displays and then crashes, and now you're saying it crashes on the second line of the button code!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

      Since it doesn't crash without the header color, take back the file without the header color…..
      0
    2. vieuxray
       
      Re,

      I've tried all the versions and it's not working.
      So I open the file, I click on the button, the list displays fine, header in red, text white.

      I maintain that this is what I do every time, I click on the button, the list appears fine and then nothing afterwards.

      With the colored list it works
      with the header it doesn't work, I crash
      with both together, I crash

      The purpose of my post was to have the ability to change the color of the header, it's glitching

      Given the complexity of the code, we might need to check the compatibility with Excel 2007 on Windows 10

      I still think it's the display of the header that's causing us trouble, but that's just my opinion.

      Thank you for your help

      Best regards, Ray
      0
    3. f894009 Posted messages 17417 Registration date   Status Member Last intervention   1 717
       
      Re,

      Excel 2007 version on Windows 10

      This is the version I'm using and no problems!!!!

      but that's just my opinion
      Re-read the last line of my previous post.........
      0
  9. vieuxray
     
    Re

    Your last line tells me:
    Since it doesn't crash without the header color, take the file without header color…

    Okay, but that's not in line with my request. What I want is to be able to modify the header color. Your discovery was fine, but unfortunately it bugs out.

    Have a good evening.
    0
    1. f894009 Posted messages 17417 Registration date   Status Member Last intervention   1 717
       
      Re,
      It may not go in the direction of your business, but it doesn't work!!
      So it's up to you to decide!!!!
      0
  10. vieuxray
     
    Hello f894009,

    Thank you for your response, so I'll drop it, it's not a big deal or essential.

    Wishing you all the best and thanks again for your help.

    Have a good day.

    Best regards, Raymond
    0
    1. f894009 Posted messages 17417 Registration date   Status Member Last intervention   1 717
       
      Hello,

      There is a way to have the "headers" in color, place labels at the location of the listview headers, and apply any color you want. It's just a matter of positioning the said labels; you can weigh the advantages and disadvantages.
      0
    2. vieuxray
       
      Re

      I intended to do it like this; I'll try to see how it goes as soon as possible.
      I'm switching internet providers at 2:30 PM, and I'll let you know the results.

      Have a good day, talk to you later.

      Best regards, Ray
      0
  11. vieuxray
     
    Hello f894009,

    I switched to fiber, and it seems to be working fine.

    Well, I tried to place a Label in the foreground on Listview1
    but I'm having an issue and can't seem to do it.
    It's as if the bring to front and send to back commands are disabled.
    I've already done plenty of drawings using bring to front and send to back without any problems, so I don't understand why it's not working anymore.
    Everything on my PC is functioning well, just like before changing providers, not even an error.
    Otherwise, it should be fine for the Label.

    Thanks to you, and have a nice evening.
    Best regards, Ray
    0