windows forms tree view nodes 


I have a windows forms with tree nodes. Every time there is a new node added to it, it should show a different color for upto 5 days. So that it will be known to users that these are new things added to forms.

Can someone tell me how is this possible?

1 Answer: 

1st solution : I don't know if it is the best way, but you could store the date of the creation of the new node in a database.

Then, when you refresh your TreeView, use something like this :

For Each node In TreeView.Nodes
    ' remove 5 days from today's date
    ' --> make sure that you use the good date format
    If field >= today.AddDays(-5) then
        TreeView.Nodes(i).ForeColor = Color.Red
    End If


2nd solution : Maybe you could create new tree nodes depending on the current date.

When you add a new node, make sure you change it's name and not it's text property. Then you can create an array with all your nodes and loop through with the following condition :

If nodeName.Substring(nodeName.Length - 10) >= CStr(Date.Today.AddDays(-5)) Then ...