BoldSignEasily embed eSignatures in your .NET applications. Free sandbox with native SDK available.
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
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
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
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
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
<Syncfusion:GridTextColumn MappingName="EmployeeArea" AllowFiltering="True" ShowToolTip="True" ShowHeaderToolTip="True"/>
|