11093 : Calculated columns in a databound Grid

Question

 

I am using the OnBeforeDSToCell event to format some data to be displayed in the grid.  But I want one of my columns to be calculated based on two other columns – how can I do this?

 

Answer

 

Since the columns are filled from 0 to n, you cannot read the x+1 column when handling OnBeforeDSToCell for column x.< ?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

But I suggest that you get your data from the datasource instead:

 

    void NodeDataConnect_OnBeforeDSToCell(NodeDataConnect aNodeDataConnect, CellAndDSArgs args)
    {
      if (args.Cell.Column.Index==theCellCalclulatedFromTwoOtherValues)
        args.Value=(args.CurrencyManagerListItem as DataRowView).Row[“Col1”].ToString()+(args.CurrencyManagerListItem as DataRowView).Row[“Col2”].ToString();
    }

10969 : The OnTimeItemAreaMouseWheel is not being called at all when I scroll the wheel over the TimeItemArea?

Question

I am handling the OnTimeItemAreaMouseWheel event. However,  the handler is not being called at all when I scroll the wheel over the TimeItemArea. Do I have to do anything special to activate this event?

 

Answer

 

Some mouse events (the wheel events included) will not fire unless the control has keyboard focus.

 

We will look into a permanent solution but in the mean time add a Focus call in mouse down:

gantt1.OnTimeItemAreaMouseDown += new MouseEventHandler(gantt1_OnTimeItemAreaMouseDown);

void gantt1_OnTimeItemAreaMouseDown(object sender, MouseEventArgs e)
{
  gantt1.TimeItemArea.Focus();
}

 

11019 : OnTimeItem_AfterMove event, the TimeItemEventArgs returns 0 in its X and Y fields?

Question

 

I am trying cause an interaction between two objects (represented by timeitems in the Gantt) that is triggered when one timeitem is moved on top of another. When trying to implement this by using the OnTimeItem_AfterMove event, the TimeItemEventArgs returns 0 in its X and Y fields. This is not good, since I am trying to find the “lower” timeitem by using the Gantt.TimeItemFromPoint method.< ?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

1) Why does the TimeItemEventArgs return these values?

2) If this is not fixable, how do I find the relevant timeitem?

 

Answer

 

1) The mouse position is not relevant after the mouse button is released, and the draw rectangle of the time item is not updated until the next render-sweep, what is valid here is the Start and Stop of the time item (collisiondetection may affect Y pixel pos, datescaler changes my change X pixel pos)

 

2) In the AfterMove the Start and Stop is updated. You can use those along with the DateScaler.TimeToPixel to get the X position and from that look for the time item that is on that position with TimeItemFromPoint.

 

11010 : Is there a way to show more than one header-line (more than one column) and / or mantain the Cell layout in the header?

Question


We have an application that shows more than a single collumn in the Grid, and each Cell in a different colour, but when switching to Schedule Mode, the colours and other columns are not shown in the header. Is there a way to show more than one header-line (more than one column) and / or mantain the Cell layout in the header? Thank you.

 

Answer


You can change the header cell layout by setting the GridColumn.ColumnCell.CellLayout to the CellLayout of your choice. The header cells use the HeaderBackgroundColor, HeaderBackgroundGradiantColor  properties for colors, besides that they work the same way.< ?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

10944 : gridNode.Expanded = true doesnt seem to be work in Gantt_ASP?

Question

I have multiple rows on the GTP grid, where each row can have any number of child rows. It should be possible for the user to set which rows need to be expanded and which need not. However, the gridNode.Expanded = true doesnt seem to be working.
Also, its been noticed that in web component, all the rows are always collapsed when its loaded. Please provide pointers on what needs to be done.

Answer

Expanded/Collapsed state is stored in ViewState. So in order to change the client view it is not enough to set the GridNode.Expanded state.
You must instead use Gantt_ASP.Get/SetExpandedStatusForGridNode

    public bool GetExpandedStatusForGridNode(GridNode aGridNode)

Can be used in PageLoad more or less like this (This code does not check for postback so it will the effect that collapse appear not to work) 

      Gantt_ASP1.Gantt.Grid.Refresh(); // Makesure the grid is rendered and the datasources get initiated
      foreach (GridNode gn in Gantt_ASP1.Gantt.Grid.RootNodes)
      {
        Gantt_ASP1.SetExpandedStatusForGridNode(gn,true);
      }

11021 : Im using Gantt_Asp but everytime I modify a timeitem I have a postback and I lose my f1.dataset values

Question

I’m using Gantt_Asp but everytime I modify a timeitem I have a postback and I lose my f1.dataset values

 

Answer

 

This is by design, the ASP.NET model is stateless and the SessionState is there to help you to handle that.

What you need to do is to, depending on your design criterias, is to cache the dataset you use and restore it for postback events. This is shown in the LetsBuild_ samples series available here http://www.plexityhide.nu/ajaxdemo/LetsBuild_ProjectPlanner.aspx

 

In short this is done like this:

 

    protected void Page_Load(object sender, EventArgs e)
    {

      if (Page.Session[“loaded_proj”] == null || (bool)(Page.Session[“loaded_proj”]) == false)
      {

 
 // OK, New user connect to your DB and fetch the data…

        f1.dataSet1.ReadXml(Page.MapPath(“.\\App_Data\\project.xml”));
        System.IO.MemoryStream ms = new System.IO.MemoryStream();
        f1.dataSet1.WriteXml(ms);
        Page.Session.Add(“thedata_proj”, ms);
        Page.Session.Add(“loaded_proj”, true);
      }
      else
      {
 // Returning user, get the cached dataset rather than fetching it again
        System.IO.MemoryStream ms = Page.Session[“thedata_proj”] as System.IO.MemoryStream;
        ms.Position=0;
        f1.dataSet1.ReadXml(ms);
      }
     
….
      }

 

 

10933 : Why does the GTP.net OnTimeItemAreaKeyDown event neverfire?

< ?xml:namespace prefix = o />Question

 

Why does the GTP.net OnTimeItemAreaKeyDown event never fire?< ?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

 

I need detect “< ?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />del” key and delete TimeItemLinks.Select SelectedLink

 

Answer

 

This event only fires if a control has Focus, and default we do not give keyboard focus to the time item area since it takes focus from the grid (this may very well change in the future when we implement key navigation i the time items)

 

The workaround is to give focus to the TimeItemArea in the MouseDown event:

 

   private void gantt1_OnTimeItemAreaMouseDown(object sender, MouseEventArgs e)
    {
      gantt1.TimeItemArea.Focus();
    }
 
    private void gantt1_OnTimeItemAreaKeyDown(object sender, KeyEventArgs e)
    {
      MessageBox.Show(“key down”);

    }

 

10921 : Is it possible to have the root node point to one table and the sub node point to a different table. These are nodes on a grid of the gantt chart

Question

Is it possible to have the root node point to one table and the sub node point to a different table. These are nodes on a grid of the gantt chart

Answer

This is a very good question. Since each SubNode collection has its own datasource property you can easily bind to a different table, but what if the new table does not share the field definitions of the root table?

For each row we will look on the columns to see what field to use for each column.

So we need a way to override the fields used for the subnodes that comes from another table.

To do this you use the GridNode.NodeDataConnect.ColumnToFieldMapperHash explained like this in the help file:

Set columnToFieldMapperHashUse to true if you want to provide your own ColumnToFieldMapperHash different from the one specified in GridColumn.DataSourceColumn. This is likely what you want to do if you have different definitions on the dataviews on subnodes than the definition on the rootnodes. Add mapping with ColumnToFieldMapperHash.Add(“GridColumn.DataSourceColumn name”,”Name of field in dataview”) Note: if ColumnToFieldMapperHashUse=false the ColumnToFieldMapperHash is ignored

10927 : We are using user drawn links in the Gantt_ASP and it is too hard to the links

Question

We are using user drawn links in the Gantt_ASP and it is too hard to select the links, especially when they are above< ?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

TimeItems or have a length of 0. Is there a easy way to get a larger

selection area and to have a preference of links above TimeItems?

 

Answer

When investigating this we found that the comment on the UserDrawLink was very brief, and we have extended it to this:


/// <summary>

/// Fired when link with drawstyle=user need to be drawn.

/// There are two passes to link drawing. First there is the normal draw, the e.G is assigned,

/// and you simply draw the Graphics object supplied. Second there is the selection region pass,

/// this is recongnised by e.G==null and e.BoundingRegion is assigned. Now you can fill the region

/// that is used to decide if a click is on a link or not.

/// </summary>

public event UserDrawLinkEvent OnUserDrawLink;

 

This gives that your code can/should look like this to enable the selection shadow of userdrawn timeitemlinks:

 

    private void OnUserDrawLink(Gantt aGantt, UserDrawLinkEventArgs e)

    {

        Rectangle startItemRect = e.Link.Start.DrawRect();

        Point start = new Point();

        start.Y = e.StartPoint.Y;

        start.X = startItemRect.X + (int)(startItemRect.Width * ((double)e.Link.UserReference) / 100.0);

 

        if (e.G==null)

        {

          ASPGantt.Gantt.TimeItemLinks.DrawCommonLinks(e.G, start, e.TargetPoint, e.Link,e.BoundingRegion);

        }

        else

        {

          ASPGantt.Gantt.TimeItemLinks.DrawCommonLinks(e.G, start, e.TargetPoint, e.Link);

        }

    }

 

… This will give a better feedback of clicked links.

Mind you that we currently have no solution for editable timeitems taking precedence over link clicks, other than making those time items not editable.

 

 

And this also explains how you can increase the sensitive of user drawn links when it comes to selection: Just make the region bigger! Try this in the code above:

        if (e.G==null)

        {

          ASPGantt.Gantt.TimeItemLinks.DrawCommonLinks(e.G, start, e.TargetPoint, e.Link,e.BoundingRegion);

          // To make the region bigger so that the selection can be made easier try this:

          Point p1=start;

          Point p2=e.TargetPoint;

          p1.Offset(2,2);

          p2.Offset(2,2);

          ASPGantt.Gantt.TimeItemLinks.DrawCommonLinks(e.G, p1, p2, e.Link, e.BoundingRegion);

         

        }

        else

        {

          ASPGantt.Gantt.TimeItemLinks.DrawCommonLinks(e.G, start, e.TargetPoint, e.Link);

        }

 

 

 

Another question on user drawn links is: Maybe I only want to do some slight change to where the link start or end on a time item, but I do not want to implement the whole Z-style drawing on my own. Can I do that?

 

Yes; go like this

 

        void gantt1_OnUserDrawLink(Gantt aGantt, UserDrawLinkEventArgs e)

        {

            // When drawing links on your own, you may want to be totally free,

            //or you may want to make a few changes and then call the standard drawing:

           

           

            // When sending in null on Link value , the attributes for style and color are taken from these properties

            aGantt.TimeItemLinks.CreationTimeItemLinkDrawStyle=TimeItemLinkDrawStyle.ZStyle;

            aGantt.TimeItemLinks.CreationTimeItemLinkColor=Color.Green;

 

            if (aGantt.MouseMoveKind == MouseMoveKind.none)

                e.TargetPoint = new Point(e.TargetPoint.X, e.TargetPoint.Y + 10);

 

            // When sending null on LinkValue to aGantt.TimeItemLinks.DrawCommonLinks the logic will go only on pixel points

            if (e.G == null)

                aGantt.TimeItemLinks.DrawCommonLinks(e.G, e.StartPoint, e.TargetPoint, e.Link, e.BoundingRegion);

            else

                aGantt.TimeItemLinks.DrawCommonLinks(e.G, e.StartPoint, e.TargetPoint, null);

 

        }

 

 

11061 : Multiselect in the TimeItemArea

Question

I know you can multiselect time items by holding the ctrl key while clicking them, and that you can get to all selected time items by the method gantt1.GetSelectedTimeItems().

But what if I do not allow multi select? How can I stop it?

Answer

To effectively stop multiselect for the TimeItems go like this:< ?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

 

    gantt1.OnTimeItem_SelectionChanged += new TimeItemEvent(gantt1_OnTimeItem_SelectionChanged);

 

    void gantt1_OnTimeItem_SelectionChanged(Gantt aGantt, TimeItemEventArgs e)

    {

      if (e.TimeItem.Selected)

      {

        foreach(TimeItem ti in gantt1.GetSelectedTimeItems())

        {

          if (ti!=e.TimeItem)

            ti.Selected=false;

        }

      }

    }