Setting the foreground color of a row based on pre-defined conditions.
I have done the following using the advice/example from the web:-
1) Added a listbox (listBox1) to a form and set the DrawMode = OwnerDrawFixed.
2) Added the following to the immediately following InitializeComponent();
listBox1.DrawItem +=
new System.Windows.Forms.DrawItemEventHandler(this.lis tBox1_DrawItem);
3) In Form1_Load, I have added the following to the listBox1 -
listBox1.Items.Add("ABC Company");
listBox1.Items.Add("DEF Company");
listBox1.Items.Add("GHI Company");
listBox1.Items.Add("JKL Comapny");
listBox1.Items.Add(MNO Company");
4) I have also build up an arrayList while adding items to listBox1 so that the items correspond to the listBox1 item. The arrayList contains the following in formation -
arrayList[0] = "Normal";
arrayList[1] = "Active";
arrayList[2] = "Active";
arrayList[3] = "Other";
arrayList[4] = "Normal";
5) Now I want the items appearing in listBox1 to show different color depending on the text in arrayList (eg, Color.Blue for "Normal", Color.Red for "Active", Color Gray for "Other"). In other words, when the listBox1 is populated, the following will be displayed-
ABC Company - in blue
DEF Company - in red
GHI Company - in red
JKL Comapny - in gray
MNO Company - in blue
QUESTION/HELP NEEDED:
How do I code the listBox1_DrawItem event so that I can achieve the result as in (5) above?
I've been researching the web but non has example similar to my problem. Any help/comment will be very much appreciated.