Add a ToolTip to a GridCommandCellElement

7 posts, 0 answers
  1. Paul Patterson
    Paul Patterson avatar
    40 posts
    Member since:
    May 2010

    Posted 29 Jul 2010 Link to this post

    Hello, I'm using RadControls for Winforms Q2 2010. 

    I have the following to create a GridCommandCellElement

    Private Sub AddTaskDetailCommand()
        Dim commandColumn As New GridViewCommandColumn
        With commandColumn
          .Name = "ViewTaskDetail"
          .FieldName = "AssetChecklistID"
          .HeaderText = String.Empty
          .Width = 30
          .AllowFiltering = False
          .AllowGroup = False
          .AllowHide = False
          .AllowResize = False
          .AllowSort = False
        End With
        RadGridView1.MasterTemplate.Columns.Insert(0, commandColumn)
        AddHandler RadGridView1.CommandCellClick, AddressOf RadGridView1_CommandCellClick
     
      End Sub

    And then the following in the CellFormatting event...

    Private Sub RadGridView1_CellFormatting(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.CellFormattingEventArgs) Handles RadGridView1.CellFormatting
     
        If (TypeOf (e.CellElement) Is GridCommandCellElement) Then
          Dim cmdCell = DirectCast(e.CellElement, GridCommandCellElement)
          Dim colName = cmdCell.ColumnInfo.Name
     
          If colName = "ViewTaskDetail" Then
            e.CellElement.ToolTipText = "View Task Details..."
            cmdCell.CommandButton.DisplayStyle = DisplayStyle.Image
            cmdCell.CommandButton.Image = My.Resources.tag_blue_edit
          End If
     
        End If
     
      End Sub

    Problem is that the tooltip is not visible when hovering over the command button in the cell. There is a small bit of padding in the cell that will display the tooltip when hovering over that, but not over the command. 

    Can seem to find a ToolTipText property for the GridCommandCellElement. Is there something I am missing?

    Cheers,

    Paully


  2. Paul Patterson
    Paul Patterson avatar
    40 posts
    Member since:
    May 2010

    Posted 29 Jul 2010 Link to this post

    My bad!! 

    There is a ToolTextProperty I can set on the CommandButton (the RadButtonElement) of the GridCommandCellElement.

    Here is what I updated...


    Private Sub RadGridView1_CellFormatting(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.CellFormattingEventArgs) Handles RadGridView1.CellFormatting
      
        If (TypeOf (e.CellElement) Is GridCommandCellElement) Then
          Dim cmdCell = DirectCast(e.CellElement, GridCommandCellElement)
          Dim colName = cmdCell.ColumnInfo.Name
      
          If colName = "ViewTaskDetail" Then
            cmdCell.CommandButton.ToolTipText = "View Task Details..."
            cmdCell.CommandButton.DisplayStyle = DisplayStyle.Image
            cmdCell.CommandButton.Image = My.Resources.tag_blue_edit
          End If
      
        End If
      
      End Sub

    Thanks anyway,

    Paully
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 30 Jul 2010 Link to this post

    Hi Paul Patterson,

    I am glad that you have found solution for this issue. If you have any further questions, do not hesitate to contact us.

    Best wishes,
    Jack
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Xavier Soares
    Xavier Soares avatar
    39 posts
    Member since:
    Jun 2008

    Posted 30 Jul 2010 Link to this post

    nevermind! My mistake. Sorry.
  6. Deborah
    Deborah avatar
    154 posts
    Member since:
    Sep 2010

    Posted 22 Apr 2011 Link to this post

    I would also like to set the Tooltiptext for my cell in the Formatting event instead of having to have special tooltipneeded event.

    However, my cell does not contain a button so the posted solution does not work for me.

    Is there a way to set the tooltip text for a cell in the Formatting event?

    Thanks!
  7. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 26 Apr 2011 Link to this post

    Hi Deborah,

    Hope you're well. The following code from the documentation shows adding a tooltip using the CellFormatting event.

    public Tooltips1()
    {
        InitializeComponent();
        DataTable t = new DataTable();
        t.Columns.Add("A");
        t.Columns.Add("B");
        t.Rows.Add("Name 1", "Code 1");
        t.Rows.Add("Name 2", "Code 2");
        this.radGridView1.DataSource = t;
        this.radGridView1.Columns["B"].IsVisible = false;
        radGridView1.BestFitColumns();
    }
      
    void radGridView1_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
    {
        if (this.radGridView1.Rows[e.CellElement.RowIndex].Cells["B"].Value != null)
        {
            e.CellElement.ToolTipText = this.radGridView1.Rows[e.CellElement.RowIndex].Cells["B"].Value.ToString();
        }
    }

    The help topic can be found here

    Hope that helps
    Richard
  8. Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 28 Apr 2011 Link to this post

    Hello Deborah,

    Thank you for writing.

    The other way to set tooltip text to the cells concerns the process of handling the ToolTipTextNeeded event of RadGridView. This event is fired only when a tooltip needs to be shown and actually this approach should work slightly better than the CellFormatting approach where you are setting the ToolTipText to all cells no matter whether they currently need tooltip text or not. We will update our documentation accordingly.

    I hope you find this information useful.

    Best wishes,
    Stefan
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top
UI for WinForms is Visual Studio 2017 Ready