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
close icon

no empty tooltips in SfDataGrid

Hi,

one of my grid columns ("Value") has a tooltip binding to another column ("Comment"), which has some empty cells.

The problem ist, that this results in empty tooltip boxes. How can I avoid empty tooltips?

I've tried to use a ToolTipTemplateSelector, with initialization in AutoGeneratingColumn:
if (e.Column.MappingName == "Value")
{
    e.Column.ToolTipTemplateSelector = new ToolTipTemplateSelector();
    e.Column.ShowToolTip = true;
}

public class ToolTipTemplateSelector : DataTemplateSelector
{
    public override DataTemplate SelectTemplate(object item, DependencyObject container)
    {
        if (item == null || container == null)
            return base.SelectTemplate(item, container);
 
        FrameworkElementFactory factory = new FrameworkElementFactory(typeof(TextBlock));
        factory.SetBinding(TextBlock.TextProperty, new Binding("Comment") { UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged });
        return new DataTemplate { VisualTree = factory };
    }
}
Thanks for your help.

Regards

Harald





10 Replies

HB Harald Betzler November 8, 2016 02:42 AM UTC

Please find attached sample solution.

Attachment: SfGridSample2_e05b57f5.zip


SV Srinivasan Vasu Syncfusion Team November 8, 2016 06:07 AM UTC

Hi Harald, 
 
Thanks for contacting Syncfusion support. 
 
We have checked your provided sample and we have modified your sample based on your requirement. You can avoid the opening of an empty Tooltip by handling the loaded event of the custom TextBlock control. 
  
Please find the modified sample. 
 
 
 
 
 
Regards,
Srinivasan 



HB Harald Betzler November 8, 2016 12:52 PM UTC

Hi Srinivasan,

this works perfect. Thank you.

Regards

Harald


SV Srinivasan Vasu Syncfusion Team November 8, 2016 06:35 PM UTC

Hi Harald, 
  
Thanks for your update. 
  
Please let us know if you need further assistance. 
  
Regards, 
Srinivasan 



HB Harald Betzler November 8, 2016 07:17 PM UTC

Hi Srinivasan,

because there are some cells with tooltips and many cells without tooltips, I want to add a notification symbol in each cell (with a tooltip respectively with a comment). This is necessary because the comment column will be hidden in the future.

The symbol could be a small red dot (or square) in the upper left corner of the cell. Or an "i" like "information".

Do you have a solution? 
(But remember, that I need the complete implementation in code behind.)

Regards

Harald


SV Srinivasan Vasu Syncfusion Team November 9, 2016 01:15 PM UTC

Hi Harald, 

We have checked your query and we have prepared a sample as per your requirement. In this sample, we have modified the GridCell style and add a notification in left corner of the particular cell using converter. 
 
Please download the sample from the below location. 


Regards, 
Srinivasan 
 
 



HB Harald Betzler November 11, 2016 10:34 AM UTC

Hi Srinivasan,

thanks for the sample. It works.

But is it really necessary to provide the complete GridCellStyle (more than 120 lines of xaml code) - only for adding a Border control (with 10 lines)?

Is there no possibility to only add the border to the current CellStyle? Ideally in code behind?

Regards

Harald


SV Srinivasan Vasu Syncfusion Team November 14, 2016 08:57 AM UTC

Hi Harald, 
 
We have checked your query and we have modified the sample based on your requirement. In this sample, we have load the Border control inside the DataTemplate instead of modifying the GridCell Style and change the visibility of UIElement(Border) inside the GridTemplateColumn based on the row data. 
 
Please refer the below Code Example.  
 
C# 
 
if (e.Column.MappingName == "Value") 
            {                
                e.Column.ToolTipTemplateSelector = new ToolTipTemplateSelector();                 
                e.Column.ShowToolTip = true; 
                DataTemplate style = Application.Current.FindResource("GridCellStyle1") as DataTemplate;                 
                e.Column.CellTemplate = style; 
                 
            } 
 
 
XAML 
 
  <DataTemplate x:Key="GridCellStyle1"> 
            <StackPanel> 
                <Border 
                                Width="10" 
                                Height="10" 
                                HorizontalAlignment="Left" 
                                VerticalAlignment="Top" 
                                SnapsToDevicePixels="True"                 
                                Visibility="{Binding Converter={StaticResource visibiltiyconverter}}"> 
                    <Path Data="F1 M 0.500,5.574 L 0.500,9.324 L 4.333,12.823 L 6.000,12.823 L 13.583,4.907 L 13.583,1.241 L 6.000,9.116 L 4.292,9.157 L 0.500,5.574 Z" 
                                  Fill="Green" 
                                  SnapsToDevicePixels="True" 
                                  Stretch="Fill" /> 
                </Border> 
                <TextBlock HorizontalAlignment="Center" Text="{Binding Path=Value}"> 
                </TextBlock> 
            </StackPanel> 
        </DataTemplate> 
 
 
Regards, 
Srinivasan 
 



HB Harald Betzler November 14, 2016 09:08 PM UTC

Hi Srinivasan,

thank you. It works perfectly.

Regards

Harald


SV Srinivasan Vasu Syncfusion Team November 15, 2016 01:52 AM UTC

Hi Harald, 
  
Thanks for your update. 
  
Please let us know if you need further assistance. 
  
Regards, 
Srinivasan 


Loader.
Live Chat Icon For mobile
Up arrow icon