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

How to make GridTextColumn MultiBinding?

Hello,

I have one Checkbox. If the checkbox is true

I want the text to be displayed as hexadecimal in the GridTextColumn, otherwise I want it to be displayed as decimal. For this, I wrote Converter as below.

class IntToHexadecimalConverter : IMultiValueConverter

    {

        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)

        {

            if (values == null) return null;


            if ((bool)values[1] == true)

                return Int32.Parse(values[0].ToString().Replace("0x", ""), NumberStyles.HexNumber);

            else return values[0];

        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)

        {

            throw new NotImplementedException();

        }

    }


It enforces UseBindingValue="true" when I implement it as below. Filtering page opening and filtering slows down if UseBindingValue is set to true. Also DataContenxt.IsHexadicamal comes as null. How can I solve these two problems?


              <Syncfusion:GridTextColumn MappingName="ID"

                                           Width="120"

                                           UseBindingValue="True">

                    <Syncfusion:GridTextColumn.DisplayBinding>

                        <MultiBinding Converter="{StaticResource IntToHexadecimalConverter}">

                            <Binding Path="ID" />

                            <Binding Path="DataContext.IsHexadecimal" />

                        </MultiBinding>

                    </Syncfusion:GridTextColumn.DisplayBinding>


5 Replies 1 reply marked as answer

DM Dhanasekar Mohanraj Syncfusion Team April 25, 2023 03:41 PM UTC

Özgür,

Currently, we are checking the reported issue with the provided details. We will check and update you with further details on April 27, 2023.

We appreciate your patience until then.

Regards,

Dhanasekar M.



ÖZ Özgür replied to Dhanasekar Mohanraj April 27, 2023 05:58 AM UTC

Thanks, waiting for your reply Dhanasekar.



DM Dhanasekar Mohanraj Syncfusion Team April 27, 2023 01:41 PM UTC

Özgür,

We have investigated the issue you reported with the details provided. Our analysis shows that the data context is not properly retrieved while performing multi-binding with the ViewModel property, leading to the reported issue.

To resolve this, we have prepared a sample for your scenario with the display binding converter alone. Please find the sample code below.

Xaml:

<syncfusion:GridTextColumn MappingName="OrderID"

                           Width="120"

                           UseBindingValue="True"

                           DisplayBinding="{Binding Path=OrderID, Converter={StaticResource IntToHexadecimalConverter}, ConverterParameter={StaticResource viewModel}}" />


Converter:

class IntToHexadecimalConverter : IValueConverter

{

    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)

    {

        if (value == null) return null;

 

        var isHexaDecimal = (parameter as ViewModel).IsHexadecimal;

        if (isHexaDecimal == true)

 

            return (Int32.Parse(value.ToString().Replace("0x", ""), NumberStyles.HexNumber)).ToString();

 

        else return value.ToString();

    }

 

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)

    {

        throw new NotImplementedException();

    }

}


C# code snippet to refresh the data grid while changing the check box state:

private void CheckBox_Click(object sender, RoutedEventArgs e)

{

    // After changing the checkbox state refresh the view in SfDataGrid

    dataGrid.View.Refresh();

}


Note:

              We should refresh the view of the grid whenever the checkbox state changes in order to trigger the converter at runtime and update the UI accordingly.


Here, we have prepared the sample and video demo for your reference, please have a look at this.

If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.


Attachment: Sample__Video_demo_81382766.zip


ÖZ Özgür April 27, 2023 01:47 PM UTC

As I mentioned in my first question, if I use UseBindingValue, there is a decrease in performance when opening the filtering page and applying the filtering. Isn't there a way to do this without using UserBindingValue?



SG Santhosh Govindasamy Syncfusion Team May 1, 2023 02:20 PM UTC

Hi Özgür,

We are not able to replicate your reported performance issue while filtering and opening the FilterControl. Please refer our shared Video and demo in our previous update. Can you please provide the below details?

  1. Customization done in your application level.
  2. Modify our provided sample to replicate the issue.

It will help us to proceed this issue further.



Marked as answer
Loader.
Live Chat Icon For mobile
Up arrow icon