GridHyperlinkColumn to display non Uri text (like a double or string).

Hello,

Is it possible in a GridHyperlinkColumn to display text that doesn't form an Uri?

I want to use the column type to display the value of a double or text property but, even it is shown, I keep getting an error message in the debug window that the type is not appropiate and can't be converted into an Uri.
With a converter can't be solved because an Uri constructor only admits a well formed url.

Also when the value is null or is an empty string another error is showin the debug window about can't create an Uri with a null.

I use the GridHyperlinkColumn to create a link so the user can click on it and open a window with other details relative to that particular row in the DataGrid.

Is there a way to achieve that? Either with the GridHyperlinkColumn or with anothert type of column.

Thanks in advance.

3 Replies 1 reply marked as answer

MA Mohanram Anbukkarasu Syncfusion Team June 9, 2021 08:17 AM UTC

Hi David, 

Thanks for contacting Syncfusion support.  

You can achieve this requirement by using GridHyperlinkColumn and CurrentCellRequestNavigate event. We have prepared a simple sample to display non URI values as a hyperlink in column and open a new window when clicking on it. The sample is available in the following link for your reference.  


Please let us know if you require further assistance from us.  

Regards, 
Mohanram A. 



DG David García June 9, 2021 09:15 AM UTC

Thank you so much for the reply back.

I was already aware of how to achive that exact functionality. What I meant is that in the debug window the following errors are shown:

System.Windows.Data Error: 1 : Cannot create default converter to perform 'one-way' conversions between types 'System.Nullable`1[System.Int32]' and 'System.Uri'. Consider using Converter property of Binding. BindingExpression:Path=ID; DataItem='EmployeeInfo' (HashCode=17096567); target element is 'Hyperlink' (HashCode=15663836); target property is 'NavigateUri' (type 'Uri')
System.Windows.Data Error: 5 : Value produced by BindingExpression is not valid for target property.; Value='2' BindingExpression:Path=ID; DataItem='EmployeeInfo' (HashCode=17096567); target element is 'Hyperlink' (HashCode=15663836); target property is 'NavigateUri' (type 'Uri')
System.Windows.Data Error: 1 : Cannot create default converter to perform 'one-way' conversions between types 'System.Nullable`1[System.Int32]' and 'System.Uri'. Consider using Converter property of Binding. BindingExpression:Path=ID; DataItem='EmployeeInfo' (HashCode=19651376); target element is 'Hyperlink' (HashCode=27863937); target property is 'NavigateUri' (type 'Uri')
System.Windows.Data Error: 5 : Value produced by BindingExpression is not valid for target property.; Value='3' BindingExpression:Path=ID; DataItem='EmployeeInfo' (HashCode=19651376); target element is 'Hyperlink' (HashCode=27863937); target property is 'NavigateUri' (type 'Uri')
System.Windows.Data Error: 1 : Cannot create default converter to perform 'one-way' conversions between types 'System.Nullable`1[System.Int32]' and 'System.Uri'. Consider using Converter property of Binding. BindingExpression:Path=ID; DataItem='EmployeeInfo' (HashCode=42644663); target element is 'Hyperlink' (HashCode=2701015); target property is 'NavigateUri' (type 'Uri')
System.Windows.Data Error: 1 : Cannot create default converter to perform 'one-way' conversions between types 'System.Nullable`1[System.Int32]' and 'System.Uri'. Consider using Converter property of Binding. BindingExpression:Path=ID; DataItem='EmployeeInfo' (HashCode=48257652); target element is 'Hyperlink' (HashCode=65737292); target property is 'NavigateUri' (type 'Uri')
System.Windows.Data Error: 5 : Value produced by BindingExpression is not valid for target property.; Value='5' BindingExpression:Path=ID; DataItem='EmployeeInfo' (HashCode=48257652); target element is 'Hyperlink' (HashCode=65737292); target property is 'NavigateUri' (type 'Uri')
System.Windows.Data Error: 1 : Cannot create default converter to perform 'one-way' conversions between types 'System.Nullable`1[System.Int32]' and 'System.Uri'. Consider using Converter property of Binding. BindingExpression:Path=ID; DataItem='EmployeeInfo' (HashCode=31665688); target element is 'Hyperlink' (HashCode=33459681); target property is 'NavigateUri' (type 'Uri')
System.Windows.Data Error: 1 : Cannot create default converter to perform 'one-way' conversions between types 'System.Nullable`1[System.Int32]' and 'System.Uri'. Consider using Converter property of Binding. BindingExpression:Path=ID; DataItem='EmployeeInfo' (HashCode=16555740); target element is 'Hyperlink' (HashCode=62618006); target property is 'NavigateUri' (type 'Uri')
System.Windows.Data Error: 5 : Value produced by BindingExpression is not valid for target property.; Value='7' BindingExpression:Path=ID; DataItem='EmployeeInfo' (HashCode=16555740); target element is 'Hyperlink' (HashCode=62618006); target property is 'NavigateUri' (type 'Uri')
System.Windows.Data Error: 1 : Cannot create default converter to perform 'one-way' conversions between types 'System.Nullable`1[System.Int32]' and 'System.Uri'. Consider using Converter property of Binding. BindingExpression:Path=ID; DataItem='EmployeeInfo' (HashCode=14783937); target element is 'Hyperlink' (HashCode=46245228); target property is 'NavigateUri' (type 'Uri')
System.Windows.Data Error: 5 : Value produced by BindingExpression is not valid for target property.; Value='8' BindingExpression:Path=ID; DataItem='EmployeeInfo' (HashCode=14783937); target element is 'Hyperlink' (HashCode=46245228); target property is 'NavigateUri' (type 'Uri')

Those errors are produced by the non Uri properties on the DataGrid. My question was if there was any way to avoid those errors.

Also if one of the vaules is null (instead of string.Empty) an exception is produced, is there a way to avoid that? (no always the value that has to be shown for strings is string.Empty, sometimes the value is null).

Excepción producida: 'System.NotSupportedException' en System.dll
System.Windows.Data Error: 23 : Cannot convert '<null>' from type '<null>' to type 'System.Uri' for 'en-US' culture with default conversions; consider using Converter property of Binding. NotSupportedException:'System.NotSupportedException: No se puede convertir UriTypeConverter desde (null).
   en System.ComponentModel.TypeConverter.GetConvertFromException(Object value)
   en System.ComponentModel.TypeConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
   en System.UriTypeConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
   en MS.Internal.Data.DefaultValueConverter.ConvertHelper(Object o, Type destinationType, DependencyObject targetElement, CultureInfo culture, Boolean isForward)'

Thanks in advance.


MA Mohanram Anbukkarasu Syncfusion Team June 10, 2021 12:11 PM UTC

Hi David, 

Thanks for the update.  

You can achieve the same by using GridTemplateColumn and SfDataGrid.CellTapped event without any binding error as shown in the following code example.  

Code example :  

<syncfusion:SfDataGrid Name="dataGrid" 
                       AutoGenerateColumns="False" 
                       CellTapped="DataGrid_CellTapped" 
                       ItemsSource="{Binding Employees}"> 
    <syncfusion:SfDataGrid.Columns> 
 
        <syncfusion:GridTemplateColumn MappingName="ID" AllowEditing="False"> 
            <syncfusion:GridTemplateColumn.CellTemplate> 
                <DataTemplate> 
                    <TextBlock Text="{Binding ID}" TextDecorations="Underline" Cursor="Hand" > 
                        <TextBlock.Style> 
                            <Style TargetType="TextBlock"> 
                                <Setter Property= "Foreground" Value="Blue"/> 
                                <Style.Triggers> 
                                    <Trigger Property ="IsMouseOver" Value="True"> 
                                        <Setter Property= "Foreground" Value="Red"/> 
                                    </Trigger> 
                                </Style.Triggers> 
                            </Style> 
                        </TextBlock.Style> 
                    </TextBlock> 
                </DataTemplate> 
            </syncfusion:GridTemplateColumn.CellTemplate> 
        </syncfusion:GridTemplateColumn> 
   </syncfusion:SfDataGrid.Columns> 
</syncfusion:SfDataGrid> 



Please let us know if you require further assistance from us. 

Regards, 
Mohanram A. 


Marked as answer
Loader.
Up arrow icon