Articles in this section
Category / Section

How to disable the hyperlink based on cell value in GridHyperlinkColumn in WPF DataGrid (SfDataGrid)?

1 min read

You can disable the HyperLink in GridHyperLinkColumn based on cell value using converter in WPF DataGrid (SfDataGrid).

XAML

<Window.Resources>
      <local:converter x:Key="converter" />
      <Style TargetType="Syncfusion:GridCell">
          <Style.Resources>
              <Style TargetType="Hyperlink">
                  <Setter Property="IsEnabled" Value="{Binding RelativeSource={RelativeSource AncestorType=Syncfusion:GridCell}, Converter={StaticResource converter}}" />
              </Style>
          </Style.Resources>
      </Style>
</Window.Resources>
<Grid>
      <Syncfusion:SfDataGrid Name="datagrid"
                               AllowEditing="True"
                               AutoGenerateColumns="False"
                               ItemsSource="{Binding EmployeeDetails}">
          <Syncfusion:SfDataGrid.Columns>
              <Syncfusion:GridHyperlinkColumn MappingName="EmployeeName" />
              <Syncfusion:GridHyperlinkColumn MappingName="EmployeeArea" />
              <Syncfusion:GridTextColumn MappingName="EmployeeAge" />
              <Syncfusion:GridTextColumn MappingName="EmployeeGender" />
          </Syncfusion:SfDataGrid.Columns>
      </Syncfusion:SfDataGrid>
</Grid>

C#

public class Converter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        var data = (value as GridCell).ColumnBase as DataColumnBase;
        var columnName = data.GridColumn.MappingName;
        if (data.GridColumn is GridHyperlinkColumn && columnName == "EmployeeArea")
        {
            var gridCell = value as GridCell;
            var getDataContext = gridCell.DataContext as Model;
            //Disable HyperLinkColumn column based on Review column false value.
            var getProperty = getDataContext.Review;
            return getProperty;
        }
        return true;
    }
    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

 

Disable the hyperlink cell value in WPF SfDataGrid

View sample in GitHub.

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied