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

DataBinding Problem

1 Answer 130 Views
CommandBar
This is a migrated thread and some comments may be shown as answers.
Christian
Top achievements
Rank 1
Christian asked on 09 Jun 2016, 03:14 PM

Hello,

I've noticed a small problem with the commandbar controls and databinding. Maybe this is not a bug, but however the commandbar controls behave different to the "normal" (Telerik) controls.

If you have something like this:

public partial class RadForm1 : Telerik.WinControls.UI.RadForm
    {
        public RadForm1()
        {
            InitializeComponent();
 
            List<myobject> source = new List<myobject>();
            BindingSource binding = new BindingSource();
 
            source.Add(new myobject(1, "a"));
            source.Add(new myobject(2, "b"));
            source.Add(new myobject(3, "c"));
            source.Add(new myobject(4, "d"));
 
            try
            {
                commandBarTextBox1.DataBindings.Add("Text", binding, "MyProperty2", true, DataSourceUpdateMode.OnValidation);
            }
            catch
            {
            }
            radTextBox1.DataBindings.Add("Text", binding, "MyProperty2", true, DataSourceUpdateMode.OnValidation);          
 
            binding.DataSource = source;
            binding.MoveLast();
        }
    }
 
    public class myobject
    {
        public int MyProperty1 { get; set; }
        public string MyProperty2 { get; set; }
 
        public myobject(int a, string b)
        {
            MyProperty1 = a;
            MyProperty2 = b;
        }
    }

the databinding of the commandbartextbox will crash but the radtextbox works fine.The problem is that the binding datasource is set after the control databinding. 

Since the radcontrols and the .net controls work fine in this case it would be nice if the commandbar controls could too.

(Why are the commandbarcontrols not derived from the radcontrols? or at least have the same base class?)

Kind Regards,

Christian

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 10 Jun 2016, 11:00 AM
Hello Christian,

Thank you for writing.

The data source is set after the binding is added to the controls. The command bar text box is a RadElement and it requires the data source to be set when the binding is added. The text box control requires the binding to have data source when it is made visible and this is why it is working with it. 

I hope this will be useful. 

Regards,
Dimitar
Telerik
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
Tags
CommandBar
Asked by
Christian
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or