This is a migrated thread and some comments may be shown as answers.

BindingNavigator - Disable delete button

1 Answer 546 Views
BindingNavigator
This is a migrated thread and some comments may be shown as answers.
Nicklas
Top achievements
Rank 1
Veteran
Nicklas asked on 26 Dec 2020, 02:44 PM

Hi,

 

I'm currently using a dataentry connected to a bindingnavigator. I'm using the below code to check when the bindingsource collection change.

The goal is to disable the delete button in the bindingnavitor when the bindingsource collection has 1 item in it like shown below:

bs.ListChanged += (s, e) =>
                    {
                        int itemCount = Convert.ToInt32(bindingNavigator.BindingNavigatorElement.PageLabel.Text.Split(' ')[1]);
                        if (itemCount == 1)
                        {
                            bindingNavigator.BindingNavigatorElement.DeleteButton.Enabled = false;
                        }
                        else
                        {
                            bindingNavigator.BindingNavigatorElement.DeleteButton.Enabled = true;
                        }
                    };

 

However, I'm having a hard time disable the delete button. As seen in the ListChanged, I'm using below code to disable the button, but it seems that it has no effect at all. Am I doing something wrong?

bindingNavigator.BindingNavigatorElement.DeleteButton.Enabled = false;

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 28 Dec 2020, 10:26 AM
Hello, Nicklas,   

The provided code snippet for disabling the delete button looks OK. However, after it is being executed, the UpdateDeleteButtonVisibility method of the RadBindingNavigatorElement is internally performed and updates the Enabled property back to true. You can use the following approach: 
        private void RadForm1_Load(object sender, EventArgs e)
        { 
            this.categoriesTableAdapter.Fill(this.nwindDataSet.Categories);

            this.bindingSource1.DataSource = this.categoriesBindingSource;

            this.radDataEntry1.DataSource = this.bindingSource1;
            this.radBindingNavigator1.BindingSource = this.bindingSource1;

            this.bindingSource1.ListChanged += bindingSource1_ListChanged;
        }

        private void bindingSource1_ListChanged(object sender, ListChangedEventArgs e)
        {
            if (this.bindingSource1.Count == 1)
            {
                this.radBindingNavigator1.BindingNavigatorElement.DeleteButton.Enabled = false;

                this.radBindingNavigator1.BindingNavigatorElement.DeleteButton.EnabledChanged += DeleteButton_EnabledChanged;
            }
        }

        private void DeleteButton_EnabledChanged(object sender, EventArgs e)
        {
            this.radBindingNavigator1.BindingNavigatorElement.DeleteButton.Enabled = false;
            this.radBindingNavigator1.BindingNavigatorElement.DeleteButton.EnabledChanged -= DeleteButton_EnabledChanged;
        }
I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
BindingNavigator
Asked by
Nicklas
Top achievements
Rank 1
Veteran
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or