DataBinding Problem

2 posts, 0 answers
  1. Christian
    Christian avatar
    21 posts
    Member since:
    May 2012

    Posted 09 Jun Link to this post

    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

  2. Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 10 Jun Link to this post

    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.
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top