Category / Section
How to edit GridHyperLinkColumn in WPF DataGrid (SfDataGrid)?
1 min read
You can load the Hyperlink in GridCell by using GridHyperlinkColumn and it is not possible to edit the GridHyperLinkColumn at run time in WPF DataGrid (SfDataGrid). But you can achieve this by loading the Hyperlink in CellTemplate of GridTextColumn like below code example.
XAML
<syncfusion:SfDataGrid AutoGenerateColumns="False" EditTrigger="OnDoubleTap" ItemsSource="{Binding EmployeeDetails}"> <syncfusion:SfDataGrid.Columns> <syncfusion:GridNumericColumn MappingName="EmployeeAge" /> <syncfusion:GridTextColumn MappingName="EmployeeName" /> <syncfusion:GridTextColumn MappingName="EmployeeGender" /> <syncfusion:GridTextColumn AllowEditing="True" MappingName="Country"> <syncfusion:GridTextColumn.CellTemplate> <DataTemplate> <ContentControl> <Hyperlink NavigateUri="{Binding HyperLink}" RequestNavigate="Hyperlink_RequestNavigate"> <TextBlock Text="{Binding Country}" /> </Hyperlink> </ContentControl> </DataTemplate> </syncfusion:GridTextColumn.CellTemplate> </syncfusion:GridTextColumn> <syncfusion:GridNumericColumn MappingName="EmployeeSalary" /> </syncfusion:SfDataGrid.Columns> </syncfusion:SfDataGrid>
C#
private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e) { System.Diagnostics.Process.Start(e.Uri.ToString()); }
In UWP, you cannot load the TextBlock inside the HyperLink control, but you can achieve you requirement by adding Hyperlink control within TextBlock like below code example.
<syncfusion:SfDataGrid ItemsSource="{Binding EmployeeDetails}" AllowResizingColumns="True" AutoGenerateColumns="False"> <syncfusion:SfDataGrid.Columns> <syncfusion:GridNumericColumn MappingName="EmployeeAge"/> <syncfusion:GridTextColumn MappingName="EmployeeGender"/> <syncfusion:GridTextColumn AllowEditing="True" Width="150" MappingName="Country"> <syncfusion:GridTextColumn.CellTemplate> <DataTemplate> <TextBlock Text="" Height="20" Width="40"> <Hyperlink NavigateUri="{Binding HyperLink}" Click="Hyperlink_Click"> <Hyperlink.Inlines> <Run Text="{Binding Country}"></Run> </Hyperlink.Inlines> </Hyperlink> </TextBlock> </DataTemplate> </syncfusion:GridTextColumn.CellTemplate> </syncfusion:GridTextColumn> <syncfusion:GridNumericColumn MappingName="EmployeeSalary"/> </syncfusion:SfDataGrid.Columns> </syncfusion:SfDataGrid>