We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

ToolTip on header

Is there a way to display tooltip on grid header?
HeaderText is wider then Width of column, so it would be fine to show it as tooltip

3 Replies

AA Arulraj A Syncfusion Team January 17, 2019 10:07 AM UTC

Hi Petr, 
 
Thank you for contacting Syncfusion support. 
 
To show the tooltip for column HeaderText you can set the Style.ShowTooltip property true and set the text for the first row which is the header row. 
 
<syncfusion:GridDataControl x:Name="dataGrid" Grid.Column="0" 
                            AutoPopulateColumns="False" 
                            ShowTooltips="True" 
                            AutoPopulateRelations="False"    
                            ColumnSizer="Star" 
                            ItemsSource="{Binding CustomerInfo}" 
                            ShowAddNewRow="False" 
                            ShowGroupDropArea="True"> 
 
public class SortColumnBehavior : Behavior<GridDataControl> 
{ 
    GridDataControl dataControl = null; 
    /// <summary> 
    /// Called when [attached]. 
    /// </summary> 
    protected override void OnAttached() 
    { 
        dataControl = this.AssociatedObject as GridDataControl;    
        dataControl.Model.QueryCellInfo += Model_QueryCellInfo; 
    } 
 
    private void Model_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e) 
    { 
        if(e.Cell.RowIndex == 0) 
        { 
            e.Style.ShowTooltip =true; 
            var column = dataControl.VisibleColumns[e.Cell.ColumnIndex]; 
            e.Style.ToolTip = column.HeaderText; 
        } 
    } 
 
    protected override void OnDetaching() 
    { 
        dataControl.Model.QueryCellInfo -= Model_QueryCellInfo; 
    } 
} 
 
Please find the sample from the below location. 
 
Arulraj A 



PB Petr Bahník January 18, 2019 11:16 AM UTC

Hello Arulraj,

thank you for your answer. It helped me, with slight modification it works for me.
There is probably problem with grids, which have more columns than VisibleColumns.Count.
I use in some cases DetailsViewTemplate , which causes creating column at first position, which is not in VisibleColumns, so I had to modify ModelQueryCellInfo method like this to prevent System.ArgumentOutOfRangeException:

 private void ModelQueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
        {
            if (e.Cell.RowIndex == 0)
            {
                var hasDetailsViewTemplate = _dataControl.DetailsViewTemplate != null;
                var columnIndex = hasDetailsViewTemplate ? e.Cell.ColumnIndex - 1 : e.Cell.ColumnIndex;                
                if (columnIndex < _dataControl.VisibleColumns.Count && columnIndex >= 0)
                {
                    e.Style.ShowTooltip = true;
                    var column = _dataControl.VisibleColumns[columnIndex];
                    e.Style.ToolTip = column.HeaderText;
                }
            }
        }

But I feel it will not work when existing some other kind of not visible columns.
Is there some better way?

And please try to drag and drop column in your sample (as written in it), you will get also exception same as my for grid with DetailsViewTemplate.



SJ Sathiyathanam Jeyakumar Syncfusion Team January 23, 2019 01:06 PM UTC

Hi Petr, 
 
Thanks for your update. 

We have checked the reported “Tooltip not shown” issue from our end with the detailsview template sample, but we unable to reproduce the issue with the given code snippets. And also, we don’t get any exception while dragging the columns.
 
 
To show the tooltips for GridDataControl you must enable the ShowToolTips as true for GridDataControl same like as below, 
<syncfusion:GridDataControl x:Name="dataGrid" 
                            Grid.Row="0" 
                            AutoPopulateColumns="False" 
                            AutoPopulateRelations="False" 
                            AllowDragColumns="True" 
                            ColumnSizer="None" 
                            ShowTooltips="True" 
 
 
Please find the testing sample from the below location. 
 
Regards, 
Sathiyathanam 


Loader.
Live Chat Icon For mobile
Up arrow icon