ToolTip or Flyover

9 posts, 0 answers
  1. Finn
    Finn avatar
    27 posts
    Member since:
    Jun 2008

    Posted 04 Jul 2008 Link to this post

    The text I'm displaying in the GridView is often much too long to fit in columns.

    How do I display flyover- or ToolTip text as I move the mouse over the grid?

    I don't see a HitTest property.

    There are a lot of events, like
    "ToolTipTextNeeded", "MouseMove", "CursorChanged" but I don't know how to use the "e" argument from those events to retrieve the cell content the cursor is over.

    I'm sure there is a most efficient way of doing this.

    Finn
  2. Dimitar Kapitanov
    Admin
    Dimitar Kapitanov avatar
    632 posts

    Posted 07 Jul 2008 Link to this post

    Hi Finn,

    Every RadItem descendant has a TooltipText property.  You can set this string property in order to display tooltips that you have set explicitly.
    Other than that you can use the ToolTipTextNeeded event to display tool tips based on dynamic conditions.
    You can also check out the "Displaying Tooltips" example for RadGridView in our Quick-Start Framework application. The example demonstrates the usage the event arguments and display tool tips inside a RadGridView.

    Regards,
    Dimitar Kapitanov
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Finn
    Finn avatar
    27 posts
    Member since:
    Jun 2008

    Posted 07 Jul 2008 Link to this post

    OK, I looked for the Quick-Start Framework application and downloaded the 045389_QSF.zip file. Is that the one? I didn't see any "Displaying Tooltips" example in there.

    This is what I need:
    Which event (mousemove?) should I use?
    How to I use the arguments from that event to get the content of the cell the mouse is on top of?

    Finn
  5. Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 10 Jul 2008 Link to this post

    Hi Finn,

    The Quick-Start Framework application comes in the installation pakcage of our controls. So, when you have the controls installed on your machine, you will be able to observe the application as well. The location where you can find it is: START >> Programs >> Telerik >> RadControls for WinForms [version] >> RadControls for WinForms Examples.

    The application which you have downloaded is just the shell application of the examples. It is published in our Code Library section due to numerous inquiries from our customers.

    As demonstrated in the real Quick-Start Framework application (section RadGridView >> Displaying Tooltips), the event which you need is the ToolTipTextNeeded. The sender is a CellElement, so you can easiliy set the the text of the ToolTip to be the Value of the CellElement:
    private void radGridView1_ToolTipTextNeeded(object sender, ToolTipTextNeededEventArgs e)  
    {  
        GridDataCellElement dataCell = sender as GridDataCellElement;  
        if (dataCell != null)   
        {  
            e.ToolTipText = dataCell.Value.ToString();  
        }  

    If you have additional questions, feel free to contact me.

    Regards,
    Nikolay
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  6. Finn
    Finn avatar
    27 posts
    Member since:
    Jun 2008

    Posted 15 Jul 2008 Link to this post

    Thank you very much. I managed to translate that to VB:

    Private Sub RadGridView1_ToolTipTextNeeded(ByVal sender As Object, ByVal e As Telerik.WinControls.ToolTipTextNeededEventArgs) Handles rgvWorkspaces.ToolTipTextNeeded

    Dim datacell As Telerik.WinControls.UI.GridDataCellElement = sender

    If Not datacell Is Nothing Then

    e.ToolTipText = datacell.Value.ToString()

    Else

    e.ToolTipText =

    "Default tool tip text goes here"

    End If

    End Sub

  7. Curtis
    Curtis avatar
    16 posts
    Member since:
    Nov 2010

    Posted 24 Mar 2011 Link to this post

    Can i set the tooltipText to be values of other columns in the same row???
  8. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 24 Mar 2011 Link to this post

    Hello,

    Yes, you can do this by just referencing the RowInfo, and then navigating to the cell from which you want the text. E.g.

    private void radGridView1_ToolTipTextNeeded(object sender, ToolTipTextNeededEventArgs e)
    {
        GridDataCellElement dataCell = sender as GridDataCellElement;
        if (dataCell != null)
        {
            if (dataCell.RowInfo.Cells["ColumnName"].Value != null)
            { e.ToolTipText = dataCell.RowInfo.Cells["ColumnName"].Value.ToString(); }
              
        }   
    }

    Hope that helps
    Richard
  9. Asif
    Asif avatar
    1 posts
    Member since:
    Mar 2015

    Posted 19 Mar 2015 in reply to Richard Slade Link to this post

    This works for me as well, but there are two things

    1) I want to display the tooltip only when the text isn't not fully visible
    2) I want to display the tooltip for column header cells as well if the column name is large and doesn't fit into current width of the column. How to do it.
  10. Hristo
    Admin
    Hristo avatar
    716 posts

    Posted 20 Mar 2015 Link to this post

    Hi Asif,

    Thank  you for writing.

    This type of behavior is not provided out of the box. However you can easily achieve the desired behavior by subscribing to the ToolTipTextNeeded event and in the handler measure the string content of the cell. Then, if the content does not fit you could show the tool tip. Please see my code snippet below:
    private void radGridView1_ToolTipTextNeeded(object sender, Telerik.WinControls.ToolTipTextNeededEventArgs e)
    {
        GridDataCellElement dataCell = sender as GridDataCellElement;
        if (dataCell != null && dataCell.Value != null)
        {
            SizeF dataCellValueSize =this.GetCellContentSize(dataCell.Value.ToString(), this.radGridView1.Font);
            if (dataCellValueSize.Width > dataCell.ColumnInfo.Width)
            {
                e.ToolTipText = dataCell.Value.ToString();
            }
            else
            {
                e.ToolTipText = "";
            }
        }
     
        GridHeaderCellElement headerCell = sender as GridHeaderCellElement;
        if (headerCell != null)
        {
            SizeF headerCelllValueSize = radGridView1.CreateGraphics().MeasureString(headerCell.Value.ToString(), radGridView1.Font);
            if (headerCelllValueSize.Width > headerCell.ColumnInfo.Width)
            {
                e.ToolTipText = headerCell.Text;
            }
            else
            {
                e.ToolTipText = "";
            }
        }
    }
     
    private SizeF GetCellContentSize(string text, Font font)
    {
        return this.radGridView1.CreateGraphics().MeasureString(text, font);
    }

    I am also sending you a gif file of the result on my end. 

    I hope this information helps. Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo Merdjanov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
UI for WinForms is Visual Studio 2017 Ready