Add events programatically (VS.NET 2k8 version)

Dec 26, 2010 at 11:39 PM
Edited Dec 26, 2010 at 11:41 PM


I try to add events from code but it fails.

I've found example but only for the VS.NET2k10 version. How should I you use ResetEvents()?

My rewritten filler method is that (called from the Window1's constructor):

IList<TEvent> res = new List<TEvent>();

res.Add(new TEvent { Job_Name = "A", Job_StatusColor = Colors.AliceBlue, Run_Description = "xxx", Run_Time = DateTime.Now.AddYears(-80), End_Time = DateTime.Now.AddYears(-78) });
res.Add(new TEvent { Job_Name = "B", Job_StatusColor = Colors.AliceBlue, Run_Description = "xxx", Run_Time = DateTime.Now.AddYears(-100), End_Time = DateTime.Now.AddYears(-80) });

XElement events = new XElement("data",
                                                from x in res
                                                orderby x.Run_Time
                                                select new XElement("event",
                                                        new XAttribute("title", x.Job_Name),
                                                        new XAttribute("start", x.Run_Time),
                                                        new XAttribute("end", x.End_Time),
                                                        new XAttribute("isDuration", true),
                                                        new XAttribute("color", x.Job_StatusColor),


But I get NullReferenceException from m_mainBand member (TimelineTray class). Maybe my Timeline hierarchy is wrong? How can I correct it?

Thanx in advance!

Nov 21, 2012 at 11:13 AM


I know this is an old thread, but I am successfully loading event data from a sql database using code very similar to yours, which I got from someone else's post elsewhere. The one thing which I noticed from the XML data file distributed with the samples is that the "color" attribute is a string, and it only accepts a very limited range of values in my world for some reason! "Green", "Red", "Black", "Cyan" etc are fine, but "Lime", "Maroon", and perhaps significantly for you, "AliceBlue" are not accepted and produce the default "Gray" color. The problem stems from the line

if (colorType.GetProperty(Event.EventColor) != null)

in TimelineDisplayEvent.cs code. It is only not null for a very restricted range of EventColor strings, and I don't understand why. Can anyone else cast any light on this?



Nov 21, 2012 at 11:24 AM
Edited Nov 21, 2012 at 11:26 AM

Sorry boj, I forgot to make my original point in the last message, which was that you didn't post your definition of the TEvent class (but I assume that your res.Add statements do actually work?), and the last item in your select list is not an XAttribute type. 

I don't know which event attribute you're trying to set with the x.Run_Description property, but it would need to be an XAttribute with an expected attribute name, ie something like

new XAttribute("recognisedattributename", x.Run_Description)); 

I think your code as is will produce invalid XML data


Nov 23, 2012 at 7:31 PM

I'd suggest to verify formats of all fields and compare them with example xmls provided for the project. it may be that color is something like Colors.Red, instead of just Red, etc. In general if you loading data from sql, why do you need to convert them to xml, so that the system parses it and generate list of TimelineEvents from this xml. I would suggest directly create list of TimelineEvents from your sql result. Hope it helps

Nov 26, 2012 at 9:23 AM

Thanks Andrew, but actually I came across the reason for this behaviour in the "Remarks" section here:

There are only 16 static members exposed in, and they are Black, Blue, Brown, Cyan, DarkGray, Gray, Green, LightGray, Magenta, Orange, Purple, Red, Transparent, White and Yellow. So the colours I mentioned as examples, Lime, Maroon and AliceBlue don't work. I tried changing some colours in the testdata.xml file supplied in your examples to satisfy myself that this was indeed the case, and sure enough, only members of the 16 colours above actually display correctly.

For my own ends I've altered your control code to use ARGB colours and it works fine retrieving these from SQL instead of the color names.