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. Visual Basic
  4. changing colors for listview rows

changing colors for listview rows

Scheduled Pinned Locked Moved Visual Basic
question
4 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.
  • F Offline
    F Offline
    FASTian
    wrote on last edited by
    #1

    Can we change the background color of the listview such that we can have row 1 which can have background color as red and row2 should have background color as blue ? Thanks

    K L 2 Replies Last reply
    0
    • F FASTian

      Can we change the background color of the listview such that we can have row 1 which can have background color as red and row2 should have background color as blue ? Thanks

      K Offline
      K Offline
      Kumar saurabh
      wrote on last edited by
      #2

      Try the following , when you are adding a item to your list view check for alternate row to apply different color. Say if current row is odd row then write ListView1.Items(itemindex).BackColor = (New System.Drawing.Color).Aquamarine and if it is even then ListView1.Items(itemindex).BackColor = (New System.Drawing.Color).Bisque Please note that this code colors background of all columns but if the last column width dosen't fills the list view then the list view background appears. So make sure that you columns fits the listview width. Kumar Saurabh

      L 1 Reply Last reply
      0
      • F FASTian

        Can we change the background color of the listview such that we can have row 1 which can have background color as red and row2 should have background color as blue ? Thanks

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

        I never coding in for this purpose, but I just have some concept from other developer on the internet. Example that you loop to call record from the database and display on the list view. 1. Loop one by one of your record to and put it in the listview row by row. 2. May be use MOD function to check for a remain value of listview index number. (if 2/2 remain 0, if 3/2 remain 1). 3. Base on the remain (only 1 and 0) they can set the background of each row in the listview at the time of loop process. Try to use google to search for this case and wish you good luck.


        A thousand mile of journey, begin with the first step. APO-CEDC Save Children Norway-Cambodia Office

        1 Reply Last reply
        0
        • K Kumar saurabh

          Try the following , when you are adding a item to your list view check for alternate row to apply different color. Say if current row is odd row then write ListView1.Items(itemindex).BackColor = (New System.Drawing.Color).Aquamarine and if it is even then ListView1.Items(itemindex).BackColor = (New System.Drawing.Color).Bisque Please note that this code colors background of all columns but if the last column width dosen't fills the list view then the list view background appears. So make sure that you columns fits the listview width. Kumar Saurabh

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

          Kumar saurabh wrote: Say if current row is odd row then write ListView1.Items(itemindex).BackColor = (New System.Drawing.Color).Aquamarine and if it is even then ListView1.Items(itemindex).BackColor = (New System.Drawing.Color).Bisque How do you determine which row is ODD or EVEN?


          A thousand mile of journey, begin with the first step. APO-CEDC Save Children Norway-Cambodia Office

          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