i am working on program on windows forms I have a listbox and I am validating data I want the correct data be added to the listbox with color green while the invalid data added with red color and I also want from the listbox to auto scroll down when an item is added and thanks
code :
try
{
validatedata;
listBox1.Items.Add("Successfully validated the data : "+validateddata);
}
catch()
{
listBox1.Items.Add("Failed to validate data: " +validateddata);
}
Assuming WinForms, this is what I would do:
Start by making a class to contain the item to add to the listbox.
Add items to your listbox using this code:
In the properties of the ListBox, set DrawMode to OwnerDrawFixed, and create an event handler for the DrawItem event. This allows you to draw each item however you wish.
In the DrawItem Event:
There are a few limitations - the main one being that you'd need to write your own click handler and redraw appropriate items to make them appear selected, since Windows won't do that in OwnerDraw mode. However, if this is just intended to be a log of things happening in your application, you may not care about items appearing selectable.
To scroll to the last item try
How about
Not really an answer to your question however you might want to look at ObjectListView. It is a ListView rather than a listbox but it is very flexible and easy to use. It could be used with a single column to represent your data
I use it to color the status of each line
http://objectlistview.sourceforge.net/cs/index.html
This is for WinForms of course.