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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Changing ForeColor Item in ListBox ...

Changing ForeColor Item in ListBox ...

Scheduled Pinned Locked Moved C#
help
7 Posts 6 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.
  • N Offline
    N Offline
    nassimnastaran
    wrote on last edited by
    #1

    Hi All ! There are some Items in my List Box(ListBox1) include "Positive" or "Negative" items ,so when I want to add Positive , "Fore color" for this Item in list Box should be Green , and if I want to add Negative item to List Box , "Fore color" for this Item in list Box should be Red :

    if (ListBox1.Items.ToString() == "Positive")
    ListBox1.ForeColor = Color.Green;
    else
    ListBox1.ForeColor = Color.Red;//if the Item is Negative

    thanks for any Help !

    D A L B 4 Replies Last reply
    0
    • N nassimnastaran

      Hi All ! There are some Items in my List Box(ListBox1) include "Positive" or "Negative" items ,so when I want to add Positive , "Fore color" for this Item in list Box should be Green , and if I want to add Negative item to List Box , "Fore color" for this Item in list Box should be Red :

      if (ListBox1.Items.ToString() == "Positive")
      ListBox1.ForeColor = Color.Green;
      else
      ListBox1.ForeColor = Color.Red;//if the Item is Negative

      thanks for any Help !

      D Offline
      D Offline
      Dan Mos
      wrote on last edited by
      #2

      That's wrong cause you set the color for the entire listbox. The best/easiest way is to set the DrawMode to OwnerDarwVariable and handle the ListBox.DrawItem event. There you could use any brush you like to draw the text. Just look for listboxDrawItem on bingle and you'll find lots of examples. :)

      All the best, Dan

      1 Reply Last reply
      0
      • N nassimnastaran

        Hi All ! There are some Items in my List Box(ListBox1) include "Positive" or "Negative" items ,so when I want to add Positive , "Fore color" for this Item in list Box should be Green , and if I want to add Negative item to List Box , "Fore color" for this Item in list Box should be Red :

        if (ListBox1.Items.ToString() == "Positive")
        ListBox1.ForeColor = Color.Green;
        else
        ListBox1.ForeColor = Color.Red;//if the Item is Negative

        thanks for any Help !

        A Offline
        A Offline
        Alan N
        wrote on last edited by
        #3

        Have you considered the ListView as an alternative to the ListBox. When set to the 'Details' view it supports per item colouring via the ListViewItem.ForeColor and .BackColor properties. Alan.

        D Wonde TadesseW 2 Replies Last reply
        0
        • A Alan N

          Have you considered the ListView as an alternative to the ListBox. When set to the 'Details' view it supports per item colouring via the ListViewItem.ForeColor and .BackColor properties. Alan.

          D Offline
          D Offline
          Dan Mos
          wrote on last edited by
          #4

          :thumbsup:

          All the best, Dan

          1 Reply Last reply
          0
          • N nassimnastaran

            Hi All ! There are some Items in my List Box(ListBox1) include "Positive" or "Negative" items ,so when I want to add Positive , "Fore color" for this Item in list Box should be Green , and if I want to add Negative item to List Box , "Fore color" for this Item in list Box should be Red :

            if (ListBox1.Items.ToString() == "Positive")
            ListBox1.ForeColor = Color.Green;
            else
            ListBox1.ForeColor = Color.Red;//if the Item is Negative

            thanks for any Help !

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            Applying different ForeColors to the items of a ListBox is pretty easy; here[^] is an article that discusses an entirely different topic, however the download will show you how to get what you want. :)

            Luc Pattyn [My Articles] Nil Volentibus Arduum

            1 Reply Last reply
            0
            • N nassimnastaran

              Hi All ! There are some Items in my List Box(ListBox1) include "Positive" or "Negative" items ,so when I want to add Positive , "Fore color" for this Item in list Box should be Green , and if I want to add Negative item to List Box , "Fore color" for this Item in list Box should be Red :

              if (ListBox1.Items.ToString() == "Positive")
              ListBox1.ForeColor = Color.Green;
              else
              ListBox1.ForeColor = Color.Red;//if the Item is Negative

              thanks for any Help !

              B Offline
              B Offline
              BobJanova
              wrote on last edited by
              #6

              You need to either custom draw the items or have a custom control (e.g. here is one by me[^]).

              1 Reply Last reply
              0
              • A Alan N

                Have you considered the ListView as an alternative to the ListBox. When set to the 'Details' view it supports per item colouring via the ListViewItem.ForeColor and .BackColor properties. Alan.

                Wonde TadesseW Offline
                Wonde TadesseW Offline
                Wonde Tadesse
                wrote on last edited by
                #7

                :thumbsup:

                Wonde Tadesse MCTS

                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