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.
Unfortunately, activation email could not send to your email. Please try again.

SfDataGrid Tooltip in one (or more) cells only

Thread ID:

Created:

Updated:

Platform:

Replies:

118390 Mar 4,2015 01:09 PM May 2,2016 08:17 AM WPF 8
loading
Tags: SfDataGrid
George Sterg
Asked On March 4, 2015 01:09 PM

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

Muthukumar Kalyanasundaram [Syncfusion]
Replied On March 5, 2015 08:56 PM

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

George Sterg
Replied On March 10, 2015 04:20 PM

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);
                   
                }
            }
        }

Muthukumar Kalyanasundaram [Syncfusion]
Replied On March 11, 2015 11:05 AM

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


George Sterg
Replied On March 11, 2015 11:16 AM

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? 

Muthukumar Kalyanasundaram [Syncfusion]
Replied On March 11, 2015 12:34 PM

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



Muthukumar Kalyanasundaram [Syncfusion]
Replied On March 12, 2015 10:09 AM

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



Silvio
Replied On April 29, 2016 06:09 PM

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 ?


Jai Ganesh S [Syncfusion]
Replied On May 2, 2016 08:17 AM

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 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;