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.

text ellipsis on DataGrid cells ?

Thread ID:

Created:

Updated:

Platform:

Replies:

123899 Apr 29,2016 04:58 PM Dec 6,2016 03:42 AM WPF 7
loading
Tags: SfDataGrid
Silvio
Asked On April 29, 2016 04:58 PM

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

Srinivasan Vasu [Syncfusion]
Replied On May 2, 2016 08:51 AM

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 


Silvio
Replied On May 19, 2016 12:59 PM

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 .....


Silvio
Replied On May 19, 2016 01:11 PM

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!


Srinivasan Vasu [Syncfusion]
Replied On May 20, 2016 03:26 AM

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 
 
 
 



Silvio
Replied On December 5, 2016 05:28 AM

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

Farjana Parveen Ayubb [Syncfusion]
Replied On December 6, 2016 03:31 AM

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 


Farjana Parveen Ayubb [Syncfusion]
Replied On December 6, 2016 03:42 AM

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


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.

;