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

text ellipsis on DataGrid cells ?

Hi,

it there a way or a style to show a text ellipsis on an SfDatagrid cell  ("..." after the cell text if it is not fully displayed) ?

I'd like to have such a functionality: when the cell size is not sufficient to display all the text content, the ellipsis is shown near the visible text and a tooltip is automatically available on the cell, containing all the complete cell value.
Otherwise, if the text is completly visibile on the cell, no ellipsis and no tooltip is generated.

Is it possible to obtain this functionality ?

Silvio

7 Replies

SV Srinivasan Vasu Syncfusion Team May 2, 2016 12:51 PM UTC

Hi Silvio, 
 
Thanks for contacting Syncfusion support. 
 
We have analyzed your query and we have prepared a sample as per your scenarios. In attached sample, we have used Converter for ToolTip.Visiblity property to show ToolTip when the text has been trimmed in SfDataGrid. Please refer the below code example and you can download sample from the below location. 
                  
C# 
public class FormatConverter : IValueConverter 
    { 
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
        { 
            if (value == null) return Visibility.Collapsed; 
 
            FrameworkElement textBlock = (FrameworkElement)value; 
 
            textBlock.Measure(new System.Windows.Size(Double.PositiveInfinity, Double.PositiveInfinity)); 
 
       // Based on Width – Show Tooltip 
 
            if (((FrameworkElement)value).ActualWidth < ((FrameworkElement)value).DesiredSize.Width) 
                return Visibility.Visible; 
            else 
                return Visibility.Collapsed; 
        } 
 
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
        { 
            throw new NotImplementedException(); 
        } 
    } 
 
XAML 
  <Window.Resources> 
        <local:FormatConverter x:Key="formatConverter" /> 
        <Style TargetType="{x:Type ToolTip}"> 
            <Setter Property="Visibility" Value="{Binding RelativeSource={RelativeSource Self},  
                Path=PlacementTarget, Converter={StaticResource formatConverter}}"/> 
        </Style>       
    </Window.Resources> 
 
 
 
 
Regards, 
Srinivasan 



SI Silvio May 19, 2016 04:59 PM UTC

Thank you for your answer.
It seemed that always was good in your idea but today I've realized that there are some big side effects in your solution.

In fact, adding these rows in my XAML:

<Window.Resources> 
        <local:FormatConverter x:Key="formatConverter" /> 
        <Style TargetType="{x:Type ToolTip}"> 
            <Setter Property="Visibility" Value="{Binding RelativeSource={RelativeSource Self},  
                Path=PlacementTarget, Converter={StaticResource formatConverter}}"/> 
        </Style>       
    </Window.Resources> 
 
I exactly have tooltips only on cells that are smaller than their content, but, on the other side, now ALL the tooltips on SfDataGrid columns are never displayed yet except when the column title content is smaller then the header cell size.
But, as you can image, I'd like my toolpis on column headers are always displayed in all situations.
So, have you any idea to solve the problem ... i.e. to have tooltips not shown if the cells are too small only for cells but NOT for headers.

Let me know .....



SI Silvio May 19, 2016 05:11 PM UTC

Probably I've resolved by myself.

I've changed your converter method with the bold inserted new lines:


    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
      if (value == null) return Visibility.Collapsed;

      if (!(value is GridCell))
        return Visibility.Visible;

      FrameworkElement textBlock = (FrameworkElement)value;

      textBlock.Measure(new System.Windows.Size(Double.PositiveInfinity, Double.PositiveInfinity));

      if (((FrameworkElement)value).ActualWidth < ((FrameworkElement)value).DesiredSize.Width)
        return Visibility.Visible;
      else
        return Visibility.Hidden;
    }

Not it seems to work as I like!



SV Srinivasan Vasu Syncfusion Team May 20, 2016 07:26 AM UTC

Hi Silvio, 
 
We have analyzed your query and you can enable the ToolTip for header cell by setting GridColumn.ShowHeaderToolTip as true. And you can skip the converter for header cell as per your code snippet. 
 
Please refer the code example. 
 
XAML 
  <Syncfusion:SfDataGrid.Columns> 
                <Syncfusion:GridTextColumn MappingName="EmployeeName"  ShowHeaderToolTip="True"/> 
                <Syncfusion:GridTextColumn MappingName="EmployeeDesignation"  /> 
                <Syncfusion:GridTextColumn MappingName="EmployeeSalary" /> 
                <Syncfusion:GridTextColumn MappingName="EmployeeArea"  /> 
                <Syncfusion:GridTextColumn MappingName="EmployeeGender"  /> 
            </Syncfusion:SfDataGrid.Columns> 
 
C# 
public class FormatConverter : IValueConverter 
    { 
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
        { 
            if (value == null) return Visibility.Collapsed; 
 
            if (!(value is GridCell)) 
                return Visibility.Visible; 
 
            FrameworkElement textBlock = (FrameworkElement)value; 
 
            textBlock.Measure(new System.Windows.Size(Double.PositiveInfinity, Double.PositiveInfinity)); 
 
            if (((FrameworkElement)value).ActualWidth < ((FrameworkElement)value).DesiredSize.Width) 
                return Visibility.Visible; 
            else 
                return Visibility.Hidden; 
        } 
 
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
        { 
            throw new NotImplementedException(); 
        } 
    } 
 
 
Please refer the below UG Link to know more about ToolTip. 
 
 
Sample Location: ToolTip 
 
Regards,
Srinivasan 
 
 
 




SI Silvio December 5, 2016 10:28 AM UTC

Dear all,

I have added to my old form a call to 

SfSkinManager.SetVisualStyle( ....)

in order to manage skin styles in my form and also to my Datagrid object.
But making this change, all the changes made to manage tooltip visibility with that converter don't work yet.
The conveter is no longer called, in fact.

What can I do to be able to continue to use my tooltip visibility converter but also have skin style management ?

Thank you very much.

Silvio


FP Farjana Parveen Ayubb Syncfusion Team December 6, 2016 08:31 AM UTC

Hi Silvio, 
Thank you for your response. 
We have analyzed your query, you can achieve your requirement by setting the Style for a ToolTip inside the SfDataGrid.Resources while applying the VisualStyles. 
Please find the below code example and sample in the following location: 
Code Example:  
<Syncfusion:SfDataGrid.Resources> 
                <Style TargetType="{x:Type ToolTip}"> 
                    <Setter Property="Visibility" Value="{Binding RelativeSource={RelativeSource Self},  
                Path=PlacementTarget, Converter={StaticResource formatConverter}}"/> 
                </Style> 
            </Syncfusion:SfDataGrid.Resources> 
 
Sample Location : 
Regards, 
Farjana Parveen A 



FP Farjana Parveen Ayubb Syncfusion Team December 6, 2016 08:42 AM UTC

Hi Silvio,  
  
Please find the sample link. 
  
Sample Location: ToolTip_WPF
 
  
Reagrds, 
Farjana Parveen A 


Loader.
Live Chat Icon For mobile
Up arrow icon