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

Leave a Reply