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#
  4. Colorizing listview rows according to value

Colorizing listview rows according to value

Scheduled Pinned Locked Moved C#
question
2 Posts 2 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.
  • K Offline
    K Offline
    kanchoette
    wrote on last edited by
    #1

    If I populate a listview with somethinglike:

    foreach (DebtorDataSet.DebtorListRow row in debtorDataSet.DebtorList.Rows)
    {
    ListViewItem item = listView.Items.Add(row.Code);
    item.SubItems.Add(name);
    item.SubItems.Add(row.IsPostcodeNull() ? "" : row.Postcode);
    item.SubItems.Add(row.IsTelephoneNull() ? "" : row.Telephone);
    }

    How can I set the backcolor of a row to red if row.Telephone is null please?

    U 1 Reply Last reply
    0
    • K kanchoette

      If I populate a listview with somethinglike:

      foreach (DebtorDataSet.DebtorListRow row in debtorDataSet.DebtorList.Rows)
      {
      ListViewItem item = listView.Items.Add(row.Code);
      item.SubItems.Add(name);
      item.SubItems.Add(row.IsPostcodeNull() ? "" : row.Postcode);
      item.SubItems.Add(row.IsTelephoneNull() ? "" : row.Telephone);
      }

      How can I set the backcolor of a row to red if row.Telephone is null please?

      U Offline
      U Offline
      usermans
      wrote on last edited by
      #2

      Well, The method ListViewItem.SubItems.Add() can take a simple string to create a subitem, but it also can take a ListViewItem.ListViewSubItem object to do the same thing. So, you can create ListViewItem.ListViewSubItem subitem, set its BackColor property to whatever you want, and then add it to the SubItems collection of your ListViewItem

      ListViewItem.ListViewSubItem it1 = new ListViewItem.ListViewSubItem();
      it1.BackColor = Color.Red;
      item.SubItems.Add(it1);

      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