When is the databinding process complete

2 posts, 0 answers
  1. Ervis
    Ervis avatar
    5 posts
    Member since:
    Oct 2012

    Posted 20 Dec 2012 Link to this post


    I have simple scenario in which a RadDropDownList  is populated from a small table in a database. After it has been populated if needed I need to select the Item or index or display value programmatically. 
    Also there is no problem with diplaying the items the items and the selection process works fine, items are diplayed in order.

    I have tried to set all the fields that I can with respect to the databinding
    here is the windows autogen code for the form where the dropdown resides
              // MachineTypeDropDownList
              this.MachineTypeDropDownList.AutoCompleteDisplayMember = "M_Type";
              this.MachineTypeDropDownList.AutoCompleteValueMember = "MachineID";
              this.MachineTypeDropDownList.DataBindings.Add(new System.Windows.Forms.Binding("SelectedIndex", this.machineDataBindingSource, "MachineID", true));
              this.MachineTypeDropDownList.DataBindings.Add(new System.Windows.Forms.Binding("SelectedItem", this.machineDataBindingSource, "M_Name", true));
              this.MachineTypeDropDownList.DataBindings.Add(new System.Windows.Forms.Binding("SelectedValue", this.machineDataBindingSource, "MachineID", true));
              this.MachineTypeDropDownList.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.machineDataBindingSource, "M_Name", true));
              this.MachineTypeDropDownList.DataSource = this.machineDataBindingSource;
              this.MachineTypeDropDownList.DisplayMember = "M_Type";
              this.MachineTypeDropDownList.Location = new System.Drawing.Point(182, 52);
              this.MachineTypeDropDownList.Name = "MachineTypeDropDownList";
              this.MachineTypeDropDownList.Size = new System.Drawing.Size(136, 20);
              this.MachineTypeDropDownList.TabIndex = 0;
              this.MachineTypeDropDownList.Text = "System.Data.DataViewManagerListItemTypeDescriptor";
              this.MachineTypeDropDownList.ValueMember = "MachineID";
              this.MachineTypeDropDownList.DataBindingComplete += new Telerik.WinControls.UI.ListBindingCompleteEventHandler(this.MachineTypeDropDownList_DataBindingComplete);
              this.MachineTypeDropDownList.Initialized += new System.EventHandler(this.MachineTypeDropDownList_Initialized);

    In the form constructor  InitializeComponent() is called after that I try to set the value of selected item of dropdown.
    at this point Items count is still 0 

    i have tried to use the lisener for databound compeleted but items are still 0
    private void MachineTypeDropDownList_DataBindingComplete(object sender, Telerik.WinControls.UI.ListBindingCompleteEventArgs e)
               System.Diagnostics.Debug.WriteLine("this.MachineTypeDropDownList.DropDownListElement.Items  --------------------------------" + this.MachineTypeDropDownList.DropDownListElement.Items.Count);
               System.Diagnostics.Debug.WriteLine("this.MachineTypeDropDownList.Items  --------------------------------" + this.MachineTypeDropDownList.Items.Count);

    I get the same result after when i try
    private void MachineTypeDropDownList_Initialized(object sender, EventArgs e){}

    My question is at what point , or what event signals that the binding process is complete and further manipulation of the dropdownlist can comence?
    Why is it that by the end of the form contructor code,  the binding has not happened yet.

    Thank you very much for any pointers to understand the telerik framework better
  2. Peter
    Peter avatar
    1160 posts

    Posted 21 Dec 2012 Link to this post

    Hello Ervis,

    Thank you for writing.

    I would like to suggest to set the RadDropDownList's BindingContext property before the data binding - it is necessary for the items creating. Usually the BindingContext is set when control is added to the form. 

    For example:
    this.MachineTypeDropDownList.BindingContext = new System.Windows.Forms.BindingContext();
    this.MachineTypeDropDownList.DataSource = this.machineDataBindingSource;

    For more information about BindingContext please refer to the following article - Winforms BindingContext

    I hope this helps. Let me know if you have additional questions.

    the Telerik team
    Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
Back to Top