10113 : How to get to the cell values when I have a particular TimeItem?

Question

How do i get the cell values of the same GridNode when I have a particular TimeItem. Consider Cell0 has “1”, Cell1 has “2” and a TimeItem for this. When I  or click the time item i want these cell values. How do i get that. plz send me some sample coding.

Answer

You go like this TimeItem.GanttRow.GridNode.GetCell(x) to reach the grid row cells associated with a given time item

10110 : Is there a way to inhibit TimeItem Overlap.

Question

Is there a way to inhibit TimeItem Overlap. I want them to be placed side-by-side. In the onTimeCollision event how may I know wich is the Item being moved/resized and wich is the one who “suffer” the overlap?

Answer

To force time items to be placed side by side you simple turn on CollisionDetection (default on). As to how to find out who is the time item mostly suffering from a detected collision; This is really a business logic defintion, we simply cannot tell what makes most sense in all cases.

What you can do is to check the Currently selected time items, it is likely that you differ between the time item that has moved into a colliding position and the time item that has been “jumped”. Simply check the Selected flag on the time items in the oncollisiondetect event, the one selected is likely the one last moved.

10099 : How do I set the DateScaler properties to display the current date as starting date.

Question

How do I set the DateScaler properties to display the current date as starting date. I tried to set the StartTime and StopTime in the DateScaler properties box but the component is not refreshing, but it sets the StopTime to the date i specified, but the start time is always Aug 5 2003. Also I want the date should display in Hours…

Answer

It has come to our attention that setting the DateScaler.StartTime and DateScaler.StopTime only works if done in such a way that StartTime is always smaller than StopTime… This is considered a bug with low priority (exists in 1.3.1). The workaround is to use the DateScaler.TimeSpanSet(Start,Stop) that will work.

Going like this…

DateTime t = DateTime.Today;
t.AddDays(1);
gantt1.DateScaler.TimeSpanSet(DateTime.Today, t);

…will give you a view of one day. Depending on the width of the Gantt-area the scale will find a value that is the best presentation for one day. To get another resolution you add more days to the view.

 

Another similair question was: I want to center the view around a specific time item:

If you know where you want the middle of the visual span (xmiddle=timeItemStart+(timeItem.Duration()/2)) you can set the Datescaler to show this by calling Gantt.DateScaler.TimeSpanSet(xstart,xstop), 

where xstart=xmiddle-(timeItem.Duration()/2) and

xstop= xmiddle+(timeItem.Duration()/2)< ?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

10100 : Is it possible to have a tool tip over the grid area?

Question

Our client require quite large pieces of text (say 40 characters) to be diplayed in a column of the grid, and I want to achieve this without using up too much of the page or using 2 lines.

Is it possible to have a tool tip over the grid area to display text that does not fit in the column? or to have the text in the grid scrolling from left to right so that it is all readable?

Answer

When you set up the GridNode you can put an object in the UserReference and pick it up in the OnMouseMove;

GridNode gn=gantt1.Grid.GridStructure.RootNodes.AddNode();
gn.GetCell(0).Content.Value=”Sample of drawing layers for time items”;
gn.UserReference=”…I put a string object here and pick it up in the tooltip …”;

then

    private void gantt1_OnGridMouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
    {
      Cell cell=gantt1.Grid.GridStructure.CellFromXY(e.X,e.Y);
      string tooltiptext=””;
      if (cell!=null)
      {
        if (cell.Node.UserReference is string)
        {
          tooltiptext=cell.Node.UserReference as string;
        }
      }
      toolTip1.SetToolTip(gantt1.Grid,tooltiptext);
    }

A followup question: Is it possible to have a tooltip ONLY when the content of the column is larger than the visible area of the column?

Go like this:


    private void gantt1_OnGridMouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
    {
      Cell cell=gantt1.Grid.GridStructure.CellFromXY(e.X,e.Y);
      string tooltiptext="";
      if (cell!=null)
      {                
        // Question: Can I show a tooltip of the text if the text does not fit in the cell..        
        if (gantt1.Grid.Graphics.MeasureString((cell.Content.Value as String),cell.Layout.Font).Width>cell.CellRect.Width) 
        {
          tooltiptext="This text did not fit in the cell: "+(cell.Content.Value as String);
        }
        
      }
      toolTip1.SetToolTip(gantt1.Grid,tooltiptext);
    }

10097 : I would expect the TimeItems displaying in alternating colors, red and blue. But still they all get the same color?

Question

I would expect the TimeItems displaying in alternating colors, red and blue. But still they all get the same color.

I have this code:

int j=1; 
private void TIDC_OnBeforeDSToTimeItem(TimeItemDataConnect aTimeItemDataConnect, TimeItemAndDSArgs args)
  {
   if (j==2)
   {
    args.TimeItem.TimeItemLayout.Color=Color.LightBlue;
    j=1;
   }
   else
   {
    args.TimeItem.TimeItemLayout.Color=Color.Red;
    j=2;
   }
  }
 
After
 
ganttrow.Layers[0].TimeItemDataConnect().OnBeforeDSToTimeItem+=new TimeItemToDSEventHandler(TIDC_OnBeforeDSToTimeItem);
in OnNodeInserted
 
I would expect the TimeItems displaying in alternating colors, red and blue. But still they all get the same color (depending on the value of j the last time  OnBeforeDSToTimeItem was called, red or blue).

Answer

With the code above you actually change the same TimeItemLayout’s color over and over.

What you want to do is to define two time item layouts; Name one “Red_TIL” and the other “BLUE_TIL” then assign these to the alternating time items.

Create the a TimeItemLayouts in your FormLoad : (you can do this in the property grid by clicking Gantt.TimeItemLayouts)

TimeItemLayout til=new TimeItemLayout();
til.TimeItemStyle=TimeItemStyle.Square;
til.BrushKind=BrushKind.GradientVertical;
til.Color=Color.FromArgb(x.Next(0,255),x.Next(0,255),x.Next(0,255));
til.GradientColor=Color.FromArgb((int)(ti.TimeItemLayout.Color.R*0.80),(int)(ti.TimeItemLayout.Color.G*0.80),(int)(ti.TimeItemLayout.Color.B*0.80));
til.Name=”Red_TIL”;

 

Then use the defined TimeItemLayouts like this in your code above
    args.TimeItem.TimeItemLayout.Color=Gantt.TimeItemLayouts.GetFromName(“Red_TIL”);

And another thing with the code above, since the TIDC_OnBeforeDSToTimeItem will be called once for Start and once for the Stop attribute, it will not work as expected.
Change the code something like this to avoid to “many” changes:

private void Form1_OnBeforeDSToTimeItem(TimeItemDataConnect aTimeItemDataConnect, TimeItemAndDSArgs args)
{
 
if (j==2 && args.PropertyDescriptorInDS.DisplayName==”Start”)
  {
     args.TimeItem.TimeItemLayout=gantt1.TimeItemLayouts.GetFromName(“TheOtherLook”);
     j=1;
  }

10098 : When connected to a database: how can I change the color of different TimeItems individually?

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”);
      }     
     
    }

 

 

 

 

10094 : I found that the Gantt component of the GTP.NET generates unnecessary tags.

Question

I found that the Gantt component of the GTP.NET generates incorrect html code adding unnecessary tags <‘/td> and <‘/table> right before <‘/span>.

Answer

Even if these tags may be redundant in certain cases, they are put in there to accommodate the ability to split a cell in two parts, one that holds the tree-button, and one to hold the content when the column has the Tree property set to true…

 

 

10095 : Want to disable clicking and dragging on the datescaler

Question

 We wanted to disable clicking and dragging on the datescalar. so We tried but failed by following reason:We failed to find the ‘OnBeforeScaleOrSpanChange’ event and the ‘BeforeScaleOrSpanChangeArg’ class.

Answer

To disable drag and zoom in the datescaler you can implement the PlexityHide.GTP.DateScaler.OnScaleChangeEvent and set the Start and Stoptime of the scaler to the Values that you want to be fixed.

You can also set the DateScaler.LowerBound and DateScaler.UpperBound to limit the date time values were you want you limits.

(Why the OnBeforeScaleOrSpanChange could not be found is not really understood. It was probably an early version problem)