-1

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?

Stephen Docy
  • 4,738
  • 7
  • 18
  • 31
ny su
  • 105
  • 2
  • 14

1 Answers1

2

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
Next

EDIT :

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 ...

nbadaud
  • 694
  • 7
  • 26
  • That is what I thought initially, but I was also not sure it this is best way. I am not sure how else can we do this ? Project growing bigger each day, users are not knowing what is new in the project. – ny su May 11 '16 at 15:48
  • I am open if someone comes up with new thoughts for this to break. – ny su May 11 '16 at 15:50
  • i edited my post to add a second solution that don't need database. Give me your opinion about it @ny su :) – nbadaud May 12 '16 at 07:22