11546 : Gantt_ASP, adding hyperlink in the grid

Question

I want to add a hyperlink “Delete” for each row in the grid

Answer

 

Add a extra column that has nothing in the DataSourceColumn:

        Gantt_ASP1.Gantt.Grid.Columns.AddNew(PlexityHide.GTP.CellType.SingleText);
        Gantt_ASP1.Gantt.Grid.Columns[1].DataSourceColumn = “”;

Then when the row is initiated, inject your callback link:

 

    void Grid_OnNodeInserted(Grid aGrid, NodeEventArgs e)
    {
        // For each new node we set up databind for subnodes…
        e.GridNode.SubNodes_DataSource = (e.GridNode.ListItemWhenDataBound() as DataRowView).CreateChildView(“subnodes”);

        string postbackref = “DELETE:” + Gantt_ASP1.GridNodeKey(e.GridNode.GetCell(1).GridNode);
        string deletecontent = “<a href=\”javascript:” + Page.ClientScript.GetPostBackEventReference(this, postbackref) + “\”>Delete</a>”;
        e.GridNode.GetCell(1).Content.Value = deletecontent;

        // and for time items
        GanttRow gr = Gantt.GanttRowFromGridNode(e.GridNode);
        gr.IncreaseRowHeightOnCollision = true;
        gr.IncreaseRow_SuggestedHeightPerItem = 20;
        gr.Layers[0].TimeItemLayout = “spacy”;
        gr.Layers[0].NameInDS_Identity = “id”;
        gr.Layers[0].NameInDS_Start = “start”;
        gr.Layers[0].NameInDS_Stop = “stop”;
        gr.Layers[0].DataSource = (e.GridNode.ListItemWhenDataBound() as DataRowView).CreateChildView(“timeitems”);
    }

Here I gave it a PostBack to the page (Page.ClientScript.GetPostBackEventReference(this…  )
So we need to make the page a IPostBackEventHandler
Just add IPostBackEventHandler behind the superclass Page:

public partial class _Default : System.Web.UI.Page, IPostBackEventHandler

Right click the IPostBackEventHandler and choose Implement interface:

Implement the handling code:

    private bool _deferActualDeleteUntilViewStateIsFullyApplied;
    private string _idToDelete;
    #region IPostBackEventHandler Members

    public void RaisePostBackEvent(string eventArgument)
    {
        string[] parts=eventArgument.Split(‘:’);
        if (parts.Length > 1)
        {
            if (parts[0] == “DELETE”)
            {
                _deferActualDeleteUntilViewStateIsFullyApplied = true;
                _idToDelete = parts[1];
            }
        }
    }

    #endregion

We do not want to delete directly, since the GridNodes are not sorted yet…
Instead we delete in the OnClientSideChangesApplied event, if applicable:

    protected void Gantt_ASP1_OnClientSideChangesApplied(object sender, EventArgs e)
    {
        if (_deferActualDeleteUntilViewStateIsFullyApplied)
        {
            GridNode gn_todelete = Gantt_ASP1.GridNodeFromKey(_idToDelete);
            if (gn_todelete != null && gn_todelete.ListItemWhenDataBound() != null)
            {

                (gn_todelete.ListItemWhenDataBound() as DataRowView).Delete();
            }
        }

     // Save the changes maybe…

    }

 

 

11229 : Resizing the TimeItem”s Region

Question

When the GanttRow.CollisionDetect and GanttRow.IncreaseRowHeightOnCollision properties are set to true, the TimeItems that are not in a collision-area are shown as filling the entire height of the now expanded row.
When trying to resize them using the suggested solution in Q10210, the drawing itself shows a regular sized TimeItem, but the text and all the events still apply to the old Region, which covers the entire height of the row.
How do I redefine the TimeItem’s Region so that I will have a regular-sized and regular-behaving TimeItem while still enjoing the benefits of showing the collisions on an increased row?

Answer

This is how to use the OnTimeItem_UserDrawBounds and  OnTimeItem_UserDraw together:

In the OnTimeItem_UserDraw event change the given Rect and Bounding  Region (make them as thin as you need)
Start with the rect and create a new region:
       e.Rect=rect;
       e.BoundingRegion = new Region(rect);

In the OnTimeItem_UserDrawBounds you must do the same(assign new  e.Rect and e.BoundingRegion), since this event Is fired when the  logic is finding out the size of the time item for other reasons  than drawing.

 

    private void buttonSetUpTestSizeOverride_Click(object sender, EventArgs e)
    {
      gantt1.OnTimeItem_UserDraw += new TimeItemEvent(gantt1_OnTimeItem_UserDraw);
      gantt1.OnTimeItem_UserDrawBounds += new TimeItemEvent(gantt1_OnTimeItem_UserDrawBounds);
      GridNode gn=new GridNode();
      gantt1.Grid.RootNodes.Insert(0,gn);
      GanttRow gr = GanttRow.FromGridNode(gn);
      TimeItem ti=gr.Layers[0].AddNewTimeItem();
      ti.Start=gantt1.DateScaler.StartTime.AddDays(5);
      ti.Stop=ti.Start.AddDays(10);
      ti.TimeItemLayout=ti.TimeItemLayout.Clone() as TimeItemLayout;
      ti.TimeItemLayout.TimeItemStyle=TimeItemStyle.User;
    }

    /// <summary>
    /// This event can help you override how a time item is perceived in the TimeItemFromXY (the active clickable area )
    /// </summary>
    void gantt1_OnTimeItem_UserDrawBounds(Gantt aGantt, TimeItemEventArgs e)
    {     
      GraphicsPath gp=new GraphicsPath();
      gp.AddEllipse(e.Rect);
      e.BoundingRegion=new Region(gp);
    }

    /// <summary>
    /// …and this event helps you draw something in that area.
    /// Note that the two areas can differ, its up to you, but it will a bit strange…
    /// </summary>
    void gantt1_OnTimeItem_UserDraw(Gantt aGantt, TimeItemEventArgs e)
    {
      GraphicsPath gp = new GraphicsPath();
      gp.AddEllipse(e.Rect);
      e.G.DrawPath(new Pen(Color.Blue),gp);     
    }

11168 : How do I use a CSS file with the GTP.NET?

Question

How do I use a CSS file with the GTP.NET?

Answer

Normally you do not want to add a css of your own to change the styles of the grid since one is generated for you based on the settings of the CellLayouts. This way you can have almost the same view in WinForms and ASP.NET.

The class names of the cells is taken from the names of the used CellLayout. You can choose to use an External style sheet or a style sheet section in the rendered page.

This property comes into play: ExternalStyles, When setting ExternalStyles to true the css stylesheet is NOT embedded into the rendered html. Intstead you must add an attribute to the head section. You will also need to create the theganttstyles.css and you can do this by calling UpdateExternalStyles with the file name of your choice. If you leave ExternalStyles to false (default) you do not need this, but on the other hand ajax does not update the head section so under certain circumstances you can run into troubles using embedded styles. 

UpdateExternalStyles,  When setting ExternalStyles to true the css stylesheet is NOT embedded into the rendered html.

Typical scenario for when to create to the css file:
Gantt_ASP_Main.ExternalStyles=true; // You have decided to use external styles, this might be set in the object inspector already LoadMainProjectData(); // You fill the Gantt with data AND you probably create some CellLayouts format grid cells
if (!File.Exists(Page.MapPath(“GanttStyle.css”))) // If you have no need for dynamic styles, the file does not need to be written every time… Gantt_ASP_Main.UpdateExternalStyles(Page.MapPath(“GanttStyle.css”)); // This call reads the CellLayouts and create the css content, and saves the file.   

 

11228 : How can I choose which printer to use?

Question

 

Using the print facilities of your object I can just launch the print preview based on the current default printer and its configurations (like paper size, etc).< ?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

 

I wonder how can do to let the user to select which printer to use and to properly configure it before printing the gantt.

 

Answer

 

Stole this more or less from MSDN:

public void Printing(string printer) {
 
try {
    streamToPrint =
new StreamReader (filePath);
   
try {
      printFont =
new Font(“Arial”, 10);
      PrintDocument pd =
new PrintDocument();
      pd.PrintPage +=
new PrintPageEventHandler(pd_PrintPage);
     
// Specify the printer to use.
      pd.PrinterSettings.PrinterName = printer;

      if (pd.PrinterSettings.IsValid) {
         pd.Print();
      }
     
else {   
         MessageBox.Show(
“Printer is invalid.”);
      }
    }
   
finally {
      streamToPrint.Close();
    }
  }
 
catch(Exception ex) {
    MessageBox.Show(ex.Message);
  }
}

 

 

11126 : Bigger jumps on datescaler scrolling

Question

I would like to change the user scroll step. I want the user to take bigger steps in time when they press the datescaler scrollbuttons. How can I go about that?

Answer

One way to solve that is to implement the OnBeforeScaleOrSpanChange event and change the deault values.

    private void buttonSetUpBiggerJumpOnTimeScroll_Click(object sender, EventArgs e)
    {
      gantt1.DateScaler.OnBeforeScaleOrSpanChange += new BeforeScaleOrSpanChangeEventHandler(DateScaler_OnBeforeScaleOrSpanChange);
    }

    void DateScaler_OnBeforeScaleOrSpanChange(DateScaler dateScaler, BeforeScaleOrSpanChangeArgs e)
    {
      if (e.DateScalerChangeKind==DateScalerChangeKind.userpan)
      {
        TimeSpan defaultjumpsize=e.NewStartTime-gantt1.DateScaler.StartTime;
        // 4 times bigger jumps than default…
        e.NewStartTime = gantt1.DateScaler.StartTime + defaultjumpsize + defaultjumpsize + defaultjumpsize + defaultjumpsize;
        e.NewStopTime = gantt1.DateScaler.StopTime + defaultjumpsize + defaultjumpsize + defaultjumpsize + defaultjumpsize;
       
      }
    }

11150 : if I want to add attributes like mouseover for the time times how do I do that?

Question

< ?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /> 

if I want to add attributes like mouseover for the time times how do I do that? Lets say for a button if I want to add a mouse over event in vb.net we can add like this

 

Button1.attributtes.add(“mouseover”,”mouseover()”)

 

I tried use ClientSideJavaScript_TimeItemInit event.

 

Is there any function avilable in plexityhide which i can add mouseover evenet for timeitem.

 

Answer

 

Sure, Go like this:

Gantt_ASP

.ClientSideJavaScript_TimeItemInit = “aImgElement.onmouseover=(function(event){alert(‘hello’);});\r\n”;

 

11123 : I want to extend the grid columns so that they always fill the space in grid

Question

 

How can I automatically extend the grid column to use up all the space in the grid?

 

Answer

 

Implement the Grid.Resize event and do something like this:

 

< ?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /> 

    void Grid_Resize(object sender, EventArgs e)

    {

      if (gantt1.Grid.Columns.SumWidth()<gantt1.Grid.Width)

      {

        gantt1.Grid.Columns.FirstVisibleColumn().Width+=gantt1.Grid.Width-gantt1.Grid.Columns.SumWidth();

      }

    }

11143 : Is there a way to change the style of selected items?

Question

Is there a way to change the style of selected items?

Answer

The built in selection highlight is limited to the TimeItemLayout.SelectHandles=color, but if you want something more fancy it is really easy to implement the OnTimeItem_SelectionChanged event and simply change the TimeItemLayout if the time item is selected or de-selected.

The event is called both for selection and de-selection, so that you can set the timeitemlayout back to the original. Just check the e.TimeItem.Selected, true=selected false=de-selected.

11108 : Can the control drag the parent TimeItem to a different row and have all its associated sub items move with it?

Question

Can the control drag the parent TimeItem to a different row and have all its associated sub items move with it?

Answer

There is no property to set to do this automatically; you will need to react to an event and move child time items according to your rules.< ?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

 

In GTP.NET I would suggest to implement OnTimeItem_ChangeRow and in this event track down the child nodes by e.TimeItem.GanttRow.GridNode.SubNodes[0..x] and for each SubNode y do Gantt.GanttRowFromGridNode(y) then loop over the layers and timeItems and move them the way you need (or move the whole GridNode to a new parent if that is what you want).

 

10974 : I’d like to use OnTimeItem_Hoover at GTP.WEB VB but its not available yet?

Question

I’d like to use OnTimeItem_Hoover at GTP.WEB VB but it’s not available yet. can you please tell me if your’re working on that?

 

Answer

When allowing for the Ajax movable Gantt_ASP.ClientTimeItems the html is different from when using non-movable time items. So what we needed to do was to find a way for you to handle both the static and the ajax case.

 

For the static case you can use the OnAreaAttributes event on the server side to inject any script reference or attribute you need.

 

But for the Ajax case that is not possible. To solve this we added a property that allows you to inject javascript code to the client side:

 

PlexityHide.GTP.WEB.

Gantt_ASP.ClientSideJavaScript_TimeItemInit = “aImgElement.title=aClientTimeItem.UserString;\r\n”;

You can add any valid javascript statement (multiple rows) here. Use this to set up MouseOver reference for you client side Hover needs.

We also added the client side UserString on client side time items for you to use to pass Time item unique data.

Initiate the UserString by implementing this new event:

void Gantt_ASP1_OnTimeItemUserStringPrepare(PlexityHide.GTP.WEB.Gantt_ASP aGantt, PlexityHide.GTP.WEB.TimeItemUserStringPrepareArgs e)
{
  e.result=
“This time item starts at “+e.ti.Start.ToLongDateString();
}