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

DataBingding not working with custom SfButton

Hello,

I created my own control based on SfButton -> MyNumericButton.

When I click on this button at runtime its value changing to 7.7 (example), but the datasource is not updated when I setup a data binding. The data binding has no effect (I use INotifyPropertyChanged too).

I attach a sample project:

  1. When you click on button, its Text should change to 7.7. This is ok.
  2. This operation should update the datasource too with data binding, but nothing happen.
  3. When I click on Check button, the MessageBox should show 7.7 too, but it is empty text.


Can you help me please why my databinding has not effect?

My binding code:

   myNumericButton1.DataBindings.Clear();

  myNumericButton1.DataBindings.Add("TextValue", MyModel2, nameof(MyModel2.SablonSzerkesztesIdoGepiButton), true, DataSourceUpdateMode.OnPropertyChanged);

I attach my sample to show this behavior.


Thank you very much for help!


BR, SZL



Attachment: Sample_f7adbea9.zip

6 Replies

SZ SZL November 15, 2022 04:42 PM UTC

Hello,

I find the soultion based on this post:

https://www.syncfusion.com/forums/177874/databinding-not-working-with-this-control

Do you have information about the fix in the future?


Thank you!

BR, SZL



GT Gokul Thanudhas Syncfusion Team November 16, 2022 02:45 PM UTC

Hi SZL,


The reported issue is not from our control side. We have faced a similar issue from our side and reported to Microsoft team regarding this. Please find the details in the below link.


Binding is not working properly when using custom delegate and Generic EventHandler for respective properties · Issue #7820 · dotnet/winforms (github.com)


We have modified the sample based on your requirement, in which we have changed the CustomDelegate to Eventhandler Delegate. Please refer to the attached sample for your reference.


Regards,

Gokul T




Attachment: Sample_1fbef34f.zip


SZ SZL replied to Gokul Thanudhas November 17, 2022 09:47 AM UTC

Hi,


Thank you very much!


I can work with these workarounds now.


BR, SZL



HN Harinath Navaneethakrishnan Syncfusion Team November 18, 2022 05:24 AM UTC

We are glad that the provided response meets your requirement. Please let us know if you need further assistance. As always, we are happy to help you out.



SZ SZL replied to Harinath Navaneethakrishnan December 4, 2022 10:06 PM UTC

Hello,


I try use this workaroung with combobox control, but unfortunatelly in this case its not working. My combobox code:


   public partial class MyComboBox : SfComboBox

    {

        public bool IsAnythingSelected { get { return this.SelectedItem != null && this.SelectedItem != DBNull.Value; } }


        public MyComboBox()

        {

            this.SelectedValueChanged += MyComboBox_SelectedIndexChanged; ;


            InitializeComponent();

        }


        private void MyComboBox_SelectedIndexChanged(object? sender, EventArgs e)

        {

            if (!SelectedItemBindableDuringSet)

            {

                selectedItemBindable = SelectedItem;

            }

        }


        #region Fix binding bug


        private object selectedItemBindable;

        private bool SelectedItemBindableDuringSet = false;


        public object SelectedItemBindable

        {

            get { return selectedItemBindable; }

            set

            {

                selectedItemBindable = value;


                if (this.SelectedItem != value)

                {

                    SelectedItemBindableDuringSet = true;

                    this.SelectedItem = value;

                    SelectedItemBindableDuringSet = false;

                }

            }

        }


        #endregion

    }


Can you help me please, why not working with combobox?


Thank you!


BR, SZL



GT Gokul Thanudhas Syncfusion Team December 6, 2022 02:05 PM UTC

The property binding with SelectedItemBindable is updated only after losing focus, but not when selected items is changed. Could you please confirm whether it is the reported issue?

Loader.
Live Chat Icon For mobile
Up arrow icon