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

SfDataGrid Tooltip in one (or more) cells only

Hello,

I am trying to add a tooltip in one particular cell based on a if selection to show a text (everything is code behind). I don't want to show any tooltip for the rest cells of the GridTextColumn. I tried using the ToolTipTemplate for the GridTextColumn but it is showing the tooltip for all the cells in the column. Any help?
Thanks

George

8 Replies

MK Muthukumar Kalyanasundaram Syncfusion Team March 6, 2015 01:56 AM UTC

Hi George,

 

Thank you for your interest in Syncfusion products.

 

If you want to add a tooltip in one particular cell based on a selection to show a text in SfDataGrid, you can use “CurrentCellActivated” event in SfDataGrid. Please refer the below code snippet,

 

C#:

this.datagrid.CurrentCellActivated += datagrid_CurrentCellActivated;

 

void datagrid_CurrentCellActivated(object sender, Syncfusion.UI.Xaml.Grid.CurrentCellActivatedEventArgs args)

{

int rowIndex = args.CurrentRowColumnIndex.RowIndex;

int columnIndex = this.datagrid.ResolveToGridVisibleColumnIndex(args.CurrentRowColumnIndex.ColumnIndex);

// Get the mapping name

var mappingName = this.datagrid.Columns[columnIndex].MappingName;

// Get the resolved current record index

var recordIndex = this.datagrid.ResolveToRecordIndex(rowIndex);

if (args.ActivationTrigger == ActivationTrigger.Mouse)

{

if (this.datagrid.View.TopLevelGroup != null)

{

// Get the current row record while grouping

var record = this.datagrid.View.TopLevelGroup.DisplayElements[recordIndex];

var data = (record as RecordEntry).Data as BusinessObjects;

var cellvalue = data.GetType().GetProperty(mappingName).GetValue(data).ToString();

// Tooltip to show the text

ToolTip toolTip = new ToolTip();

toolTip.Content = cellvalue;

toolTip.StaysOpen = false;

toolTip.IsOpen = true;

}

else

{

// Get the current row record

var record1 = this.datagrid.View.Records.GetItemAt(recordIndex);

var cellvalue = record1.GetType().GetProperty(mappingName).GetValue(record1).ToString();

ToolTip toolTip = new ToolTip();

 

toolTip.Content = cellvalue;

toolTip.StaysOpen = false;

toolTip.IsOpen = true;

}

}

}

 

Please let us know if you have any concerns.

 

Regards,

Muthukumar k


Attachment: SfDataGridTooltipSample_ed688ce1.zip


GS George Sterg March 10, 2015 08:20 PM UTC

I dont want the tooltip to be based on a selection, i want the tooltip to be shown on hover even if i have not selected the cell. In Winforms i had this:

 private void grdMainView_QueryCellStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventArgs e)
        {
           Syncfusion.Grouping.Record record = e.TableCellIdentity.DisplayElement.GetRecord();

                if (e.TableCellIdentity.Column.Name.Equals("Rate"))
                {
                    if (record.GetValue("RateChange").ToString() == "Y")
                    {
                     

                        e.Style.TextColor = System.Drawing.Color.Red;
                        e.Style.Font.Bold = true;
                        e.Style.ImageIndex = 0;
                        e.Style.CellTipText = "Rate Change .....");
                       
                    }
                    else
                    {
                        e.Style.TextColor = System.Drawing.Color.MediumBlue;
                        e.Style.Font.Bold = true;
                    }

                    ClientSpecificController.ExtendGetQueryCellStyleInfo_FormMain().Invoke(e, record, PB);
                   
                }
            }
        }


MK Muthukumar Kalyanasundaram Syncfusion Team March 11, 2015 03:05 PM UTC

Hi George,

 

If you want to show the tooltip text  for particular column while hovering the cell in the grid, you can use “ToolTipTemplate” property. Please refer the below code snippet,

 

Code:-

 

XAML:

 

<Syncfusion:SfDataGrid.Columns>

<Syncfusion:GridTextColumn MappingName="EmployeeName" AllowFiltering="True"/>

<Syncfusion:GridTextColumn MappingName="EmployeeAge" AllowFiltering="True"/>

<Syncfusion:GridTextColumn MappingName="EmployeeArea" AllowFiltering="True">

<Syncfusion:GridTextColumn.ToolTipTemplate>

<DataTemplate>

<TextBlock Text="{Binding EmployeeArea}" /> <!-- Binding Cell Value -->

</DataTemplate>

</Syncfusion:GridTextColumn.ToolTipTemplate>

</Syncfusion:GridTextColumn>

<Syncfusion:GridTextColumn MappingName="EmployeeGender" AllowFiltering="True"/>

</Syncfusion:SfDataGrid.Columns>

 

 

Please let us know if you have any concerns.

 

Regards,

Muthukumar K



GS George Sterg March 11, 2015 03:16 PM UTC

In my case, i want to show the tooltip only for a specific cell (to make it simple lets say the cell on the second row; of course it will be based on the value of the cell). I want all the the other cells ( of the  EmployeeArea mapping) with no tooltip. How can i do that? 


MK Muthukumar Kalyanasundaram Syncfusion Team March 11, 2015 04:34 PM UTC

Hi George,
 
Due to some problem on server,the sample couldn't uploaded. Please refer the attached sample.
 
Sample: SfDataGridTooltipSample___Xaml.zip
 
Regards,
Muthukumar K




MK Muthukumar Kalyanasundaram Syncfusion Team March 12, 2015 02:09 PM UTC

Hi George,

 

Thanks for the update.

 

If you want to show the tooltip text  to specific cell while hovering on that cell in SfDataGrid, you can handled the “MouseMove” event. With this event, you can get the row index and column index by using SfDataGrid.GetVisualContainer() method and set the tooltip to show the tooltip text. Please refer the below code snippet,

 

Code:

 

 

using Syncfusion.UI.Xaml.Grid.Helpers;

 

this.datagrid.MouseMove += datagrid_MouseMove;

 

ToolTip toolTip = newToolTip();

void datagrid_MouseMove(object sender, MouseEventArgs e)

{

var visualcoin = datagrid.GetVisualContainer();

var point = e.GetPosition(visualcoin);

var rowcolumnindex = visualcoin.PointToCellRowColumnIndex(point);

var rowindex = rowcolumnindex.RowIndex;

var columnindex = rowcolumnindex.ColumnIndex;

// Get the resolved current record index

var recordIndex = this.datagrid.ResolveToRecordIndex(rowindex);

 

if (rowindex == 2 && columnindex == 2)  // column - EmployeeArea

{

if (toolTip.IsOpen)

return;

// Get the current row record

var mappingName = this.datagrid.Columns[columnindex].MappingName;

var record1 = this.datagrid.View.Records.GetItemAt(recordIndex);

var cellvalue = record1.GetType().GetProperty(mappingName).GetValue(record1).ToString();

toolTip.Content = cellvalue;

toolTip.IsOpen = true;

toolTip.StaysOpen = true;

}

toolTip.IsOpen = false;

toolTip.StaysOpen = false;

}

 

 

Note:

You can get SfDataGrid.GetVisualContainer()  using this namespace  “Syncfusion.UI.Xaml.Grid.Helpers”.

 

Please refer the attached sample.

 

Sample: SfDataGridTooltipSample_-_Specific_cell.zip

 

Please let us know if you have any concerns.

 

Regards,

Muthukumar K




SI Silvio replied to Muthukumar Kalyanasundaram April 29, 2016 10:09 PM UTC

Hi George,
 
Due to some problem on server,the sample couldn't uploaded. Please refer the attached sample.
 
Sample: SfDataGridTooltipSample___Xaml.zip
 
Regards,
Muthukumar K



Dear all,

since I'm interested on using cell tooltips, I'm trying this your example:

http://www.syncfusion.com/downloads/support/directtrac/118390/SfDataGridTooltipSample___Xaml1462262888.zip

But no tooltip is displayed on "EmployeeArea" cells.
What's the problem ?



JG Jai Ganesh S Syncfusion Team May 2, 2016 12:17 PM UTC

Hi George, 
 
You can achieve your requirement to show the tooltip for a column by enabling the ShowToolTip property as true and if you want to show the HeaderTooltip then you can enable the ShowHeaderTooltip as true like below, 
 
 
<Syncfusion:GridTextColumn MappingName="EmployeeArea" AllowFiltering="True" ShowToolTip="True" ShowHeaderToolTip="True"/> 
 
 
Regards, 
Jai Ganesh S 


Loader.
Live Chat Icon For mobile
Up arrow icon