Question
When connected to a database: how can I change the color of different TimeItems individually (for instance: same resources the same color)?
Answer
Good question, how do you manage to set specific properties to data that is added automatically with databind.
For time items you willl find a TimeItemDataConnect for each layer.
It is the TimeItemDataConnect object that resolves the events in the datasource to actual time item property values. You can implement the TimeItemDataConnect.OnBeforeDSToTimeItem (the event is not available in the property grid but just type yourLayer.TimeItemDataConnect.OnBeforeDSToTimeItem+= and hit tab in VS)
In this event you can inspect that data from the datarow and you can do additional things on your time item, like setting a TimeItemLayout etc.
This event is also good for conversions, if your datarow has start and length instead of start and stop.
New: Now there is an easier way to intercept what happens each time the TimeItem is updated from the datasource: OnEachListItemWhenDataBound_TimeItem
In the sample below we use it to add TimeItemTexts:
/// <summary>
/// Our bookings are represented by TimeItems in the Schedule
/// Here we extract further information on TimeItemTexts that we want to show
/// </summary>
private void gantt1_OnEachListItemWhenDataBound_TimeItem(object GTPComponent, EachListItemWhenDataBoundArgs e)
{
if ((e.GTPObject as TimeItem).TimeItemTexts.Count==0)
{
TimeItemText tit=new TimeItemText();
tit.Text = (string) (e.CurrencyManagerListItem as DataRowView)[“Text”];
tit.TimeItemTextLayout=gantt1.TimeItemTextLayouts.GetFromName(“default”);
(e.GTPObject as TimeItem).TimeItemTexts.Add(tit);
(e.GTPObject as TimeItem).TimeItemLayout=gantt1.TimeItemLayouts.GetFromName(“default”);
tit=new TimeItemText();
tit.Text = “Booking for “+(string)((e.GTPObject as TimeItem).GanttRow.GridNode.ListItemWhenDataBound() as DataRowView)[“Name”];
tit.TimeItemTextLayout=gantt1.TimeItemTextLayouts.GetFromName(“lower”);
(e.GTPObject as TimeItem).TimeItemTexts.Add(tit);
(e.GTPObject as TimeItem).TimeItemLayout=gantt1.TimeItemLayouts.GetFromName(“default”);
}
}