Change the color of a cell in a listview column

Solved
mylord666 Posted messages 162 Status Member -  
mylord666 Posted messages 162 Status Member -
Good evening
who can tell me why I can read the cell but cannot change the color

here is my code

listview1.items(1).subitems(5).backcolor=color orange
msgbox(listview1.items(1).subitems(5).text)

thank you for your help

2 answers

  1. cs_Le Pivert Posted messages 8437 Status Contributor 730
     
    Hello,

    while looking at this site:

    https://plasserre.developpez.com/cours/vb-net/?page=ui-winforms3#LVIII-H-4

    you find this:

    'Set the background of a cell to red ListView1.Items(2).UseItemStyleForSubItems= False ListView1.Items(2).SubItem(3).BackColor= Colors.Red 'Set a row to green ListView1.Items(2).BackColor= Colors.Lime 

    --
    @+ The Woodpecker
    1
    1. cs_Le Pivert Posted messages 8437 Status Contributor 730
       
      Look closely, you missed a point after color that should be colors with an s. In programming, a space, a period, etc. changes everything!
      0
    2. mylord666 Posted messages 162 Status Member
       
      Thank you very much, I find this very interesting and useful folder. However, "colors.lime" is not accepted with an "S" at the end of color, but "color.lime." I don't know why, if you could let me know.
      Thanks again for your valuable help.
      0
  2. cs_Le Pivert Posted messages 8437 Status Contributor 730
     
    Indeed, it's a mistake on the website:

    there's a missing "s" in SubItem

    there's an extra "s" in Colors

     'Set the background of a cell to red ListView1.Items(0).UseItemStyleForSubItems = False ListView1.Items(0).SubItems(0).BackColor = Color.Red 'Set a row to green ListView1.Items(0).BackColor = Color.Lime


    If you put Option Strict On at the top of your code, the errors will show up, and you just need to right-click to fix them.

    Another tip is that if you put a dot after Color, a context menu will appear with all the colors. This applies to everything:

    ListView1.Items(0).

    for example will display SubItems

    Happy coding

    --
    @+ Le Pivert
    0
    1. mylord666 Posted messages 162 Status Member
       
      Thank you very much, it works well, bravo, and thanks again.
      0