Changing ForeColor Item in ListBox ...
-
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 Negativethanks for any Help !
-
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 Negativethanks for any Help !
That's wrong cause you set the color for the entire listbox. The best/easiest way is to set the
DrawMode
toOwnerDarwVariable
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
-
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 Negativethanks for any Help !
-
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.
-
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 Negativethanks for any Help !
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
-
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 Negativethanks for any Help !
-
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.
:thumbsup:
Wonde Tadesse MCTS