This is a migrated thread and some comments may be shown as answers.

Add a ToolTip to a GridCommandCellElement

6 Answers 181 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Paul Patterson
Top achievements
Rank 1
Paul Patterson asked on 29 Jul 2010, 05:12 PM
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


6 Answers, 1 is accepted

Sort by
0
Paul Patterson
Top achievements
Rank 1
answered on 29 Jul 2010, 05:27 PM
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
0
Jack
Telerik team
answered on 30 Jul 2010, 05:32 PM
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
0
Xavier Soares
Top achievements
Rank 2
answered on 30 Jul 2010, 08:12 PM
nevermind! My mistake. Sorry.
0
Deborah
Top achievements
Rank 1
answered on 22 Apr 2011, 04:29 PM
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!
0
Richard Slade
Top achievements
Rank 2
answered on 26 Apr 2011, 09:41 AM
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
0
Stefan
Telerik team
answered on 28 Apr 2011, 11:30 AM
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
Tags
GridView
Asked by
Paul Patterson
Top achievements
Rank 1
Answers by
Paul Patterson
Top achievements
Rank 1
Jack
Telerik team
Xavier Soares
Top achievements
Rank 2
Deborah
Top achievements
Rank 1
Richard Slade
Top achievements
Rank 2
Stefan
Telerik team
Share this question
or