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

radDataEntry - winforms UI

19 Answers 368 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
DBA
Top achievements
Rank 1
DBA asked on 02 Apr 2014, 04:00 PM
Does anyone know how to get a dropdownlist to function (bindings) on the new radDataEntry form.   I am so frustrated with the lack of examples and documentation with Telerik!  

19 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 04 Apr 2014, 11:53 AM
Hello Lloyd,

Thank you for writing.

In general case when your data source contains enumeration the drop down list will appear automatically. The default editors along with their corresponding types are described in the following article: DataEntry.

If you need to use drop down list as an editor for a custom field that is not enumeration you can change the default editor in the EditorInitializing event:
void radDataEntry1_EditorInitializing(object sender, Telerik.WinControls.UI.EditorInitializingEventArgs e)
{
    if (e.Property.Name == "Str")
    {
        RadDropDownList radDropDownList1 = new RadDropDownList();
 
        radDropDownList1.DataSource = valuesList;
        radDropDownList1.ValueMember = "Value";
        radDropDownList1.DisplayMember = "Value";
 
        radDropDownList1.DropDownListElement.StretchHorizontally = true;
 
        e.Editor = radDropDownList1;
    }
}

More information about such scenarios is available in the following article: Change auto generated editor.

I also have attached a small sample to show you how such scenario can be achieved.

Let me know if you have additional questions.

Also since you have mentioned that you are frustrated from the lack of documentation, I want to ask you to provide us with more details on what do you find missing in our documentation and examples that you would you like to see there? Your feedback is highly appreciated.
 
Regards,
Dimitar
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Michael Hildebrand
Top achievements
Rank 2
answered on 01 Jun 2015, 02:30 PM

Hello -

I have a custom dropdownlist editor working with a radDataEntry form/control. The custom dropdownlist has ID (int) and OffierName (string) properties as properties.  In my datasource setting to the radDataEntry control I point a data class that contains a property called OwnerID (int).

When I display the data entry form, the dropdownlist control appears, and it lists all the DisplayName values in dropdown. What it does not do is preselect the dropdownlist control with the OwnerID in my data class, when the radDataEntry control's datasource is set.  If I select an item in the dropdownlist, it does set the OwnerID correctly in the data class.   

How do I get the custom dropdownlist editor to preselect, when the radDataEntry control's datasource is set?

 

Note: I have the 'radDataEntry1_BindingCreating' event setup.

0
Dimitar
Telerik team
answered on 02 Jun 2015, 02:04 PM
Hi Michael,

Without the actual code I cannot say why the correct item is not selected in the dropdown editor. However, we have a complete example for this in our documentation: Change the editor to a bound RadDropDownList. If the solution there is not working for your case, I want to kindly ask you to open a support ticket where you can attach your project. This way we will be able to provide you with a proper solution.  

I hope this will be useful. 

Regards,
Dimitar
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Michael Hildebrand
Top achievements
Rank 2
answered on 02 Jun 2015, 04:16 PM

Hello Dimitar!

I have already tried the example you suggested above.  I have created another example based on the one you suggested to show my problem.  All you need to do to run it is create a windows form app with a RadDataEntry control on the form.  Here is the code...

namespace TestDDL
{
  public partial class Form1 : RadForm
  {
    private List<Supplier> supplierList;

    public Form1()
    {
      InitializeComponent();

      suplierList = new List<Supplier>();
      suplierList.Add(new Supplier(1, "(1) Exotic Liquids"));
      suplierList.Add(new Supplier(2, "(2) New Orleans Cajun Delights"));
      suplierList.Add(new Supplier(3, "(3) Tokyo Traders"));
      suplierList.Add(new Supplier(4, "(4) Norske Meierier"));
      suplierList.Add(new Supplier(5, "(5) New England Seafood Cannery"));
      suplierList.Add(new Supplier(6, "(6) Leka Trading"));

      // I create the record here to be displayed in the RadDataEntry form
      var record = new Record();
      record.SupplierItem = 3;  // I want the drop down list to initially display item 3 or 'Tokyo Traders'
                                // This is what is not working ... 

      radDataEntry1.DataSource = record;
    }

    void radDataEntry1_EditorInitializing(object sender, Telerik.WinControls.UI.EditorInitializingEventArgs e)
    {
      if (e.Property.Name == "SupplierItem")
      {
        var radDropDownList1 = new RadDropDownList();

        radDropDownList1.DataSource = suplierList;

        radDropDownList1.ValueMember = "SupplierID";
        radDropDownList1.DisplayMember = "CompanyName";

        e.Editor = radDropDownList1;
      }
    }

    void radDataEntry1_BindingCreating(object sender, Telerik.WinControls.UI.BindingCreatingEventArgs e)
    {
      if (e.DataMember == "SupplierItem")
      {
        e.PropertyName = "SelectedValue";
      }
    }

    void radDataEntry1_BindingCreated(object sender, BindingCreatedEventArgs e)
    {
      if (e.DataMember == "SupplierItem")
      {
        e.Binding.FormattingEnabled = true;
        e.Binding.Parse += new ConvertEventHandler(Binding_Parse);
      }
    }

    private void Binding_Parse(object sender, ConvertEventArgs e)
    {
      int tmpvalue;
      int? result = int.TryParse(e.Value.ToString(), out tmpvalue) ? tmpvalue : (int?)null;

      e.Value = result;
    }
  }

  public class Record
  {
    public int SupplierItem { get; set; }
  }

  public partial class Supplier
  {
    private int? _supplierID;
    private string _companyName;

    public Supplier(int? supplierID, string companyName)
    {
        this._supplierID = supplierID;
        this._companyName = companyName;
    }

    public int? SupplierID
    {
        get
        {
            return this._supplierID;
        }
        set
        {
            this._supplierID = value;
        }
    }

    public string CompanyName
    {
        get
        {
            return this._companyName;
        }
        set
        {
            this._companyName = value;
        }
    }
  }
}

0
Michael Hildebrand
Top achievements
Rank 2
answered on 02 Jun 2015, 04:22 PM

Sorry misspelt 'supplierList', just change:

private List<Supplier> supplierList;

to

private List<Supplier> suplierList;

:) Less changes :)

0
Dimitar
Telerik team
answered on 03 Jun 2015, 10:07 AM
Hello Michael,

Thank you for writing back.

This is a known issue and it is already logged in our Feedback Portal. You can track the item for status changes and add your vote for it here.

Tow workaround the issue you should set the dropdown list parent:
void radDataEntry1_EditorInitializing(object sender, Telerik.WinControls.UI.EditorInitializingEventArgs e)
{
    if (e.Property.Name == "SupplierItem")
    {
        var radDropDownList1 = new RadDropDownList();
        radDropDownList1.DataSource = suplierList;
        radDropDownList1.ValueMember = "SupplierID";
        radDropDownList1.DisplayMember = "CompanyName";
        radDropDownList1.Parent = this;
        e.Editor = radDropDownList1;
    }
}

In addition you should set the RadDataEntry data source in the form's Load event:
private void RadForm1_Load(object sender, EventArgs e)
{
    var record = new Record();
    record.SupplierItem = 3;
    radDataEntry1.DataSource = record;
}

I hope this will be useful. 

Regards,
Dimitar
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Michael Hildebrand
Top achievements
Rank 2
answered on 06 Aug 2015, 06:37 PM

I tried the work around above and it work 80% of the time.

You can test this by taking the code in the Load event and it in a Button event. When the app is run, press the button 20 times and you will see the value incorrectly displayed in the dropdownlist.

I need this fixed ASAP.  I still own the trial version of telerik, and will be buying soon. Please let me know if there is a fix! Thanks.

0
Dimitar
Telerik team
answered on 10 Aug 2015, 01:32 PM
Hello Michael,

Thank you for writing back.

I have tested this and on my side the workaround is working properly. I have attached my test project. Could please take a look at it and let me know what else I need to in order to reproduce the issue?

Thank you in advance for your patience and cooperation. 
 
Regards,
Dimitar
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Michael Hildebrand
Top achievements
Rank 2
answered on 11 Aug 2015, 12:18 PM

Hi Dimitar!

In order to see the issue, the RadDataEntry.DataSource must first be set to null.  I set it to null to clear and refresh all the fields on the RadDataEntry form - some of mine forms have 40+ fields on them.

To see the issue, replace the follow 2 lines of code in your example (in the 'for' loop):

1. record.SupplierItem = rnd.Next(5);
2. radDataEntry1.DataSource = record;

With these 4 lines of code:

1. record.SupplierItem = 6;
2. radDataEntry1.DataSource = null;
3. radDataEntry1.DataSource = record;
4. if (record.SupplierItem != 6) RadMessageBox.Show("STOP! SupplierItem changed!");

Michael

 

0
Dimitar
Telerik team
answered on 14 Aug 2015, 11:00 AM
Hi Michael,

Thank you for writing back.

I was able to reproduce the observed behavior. It appears that when the data source is reset the binding context of the control is changed as well. This resets the position 0. The solution, in this case, would be to update the items without resetting the data source (resetting the data source to update the values is a bad practice because the reset will recreate all visual controls, which is slow operation). I have attached updated version of the sample project to show you how this can be implemented. 

I hope this will be useful.

Regards,
Dimitar
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Michael Hildebrand
Top achievements
Rank 2
answered on 14 Aug 2015, 11:50 AM

This is very useful. Thank you.  I see how you are using the BindingSource.

However, when the button click code sets the SupplierItem, the form is never updated.  Here:

      record.SupplierItem = rnd.Next(5);  // Does not update form (I'm using Q1 2015)

How can I cause the form to update, without resetting the data source?

Thanks,

Michael

 

0
Dimitar
Telerik team
answered on 14 Aug 2015, 02:27 PM
Hello Michael,

Thank you for writing back.

The random object can return 0 as value and in this case, the item would not be changed (the data source does not have a value with 0 for ID). You can properly check this with the following code:
int count = 1;
 
private void button1_Click(object sender, EventArgs e)
{
    
    record.SupplierItem = count++;
    if (count == 6)
    {
        count = 1;
    }
}

In addition, I have tested this with Q1 2015 assemblies and it is working as expected.

Do not hesitate to contact us if you have other questions.
 
Regards,
Dimitar
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Andrea
Top achievements
Rank 1
answered on 10 May 2018, 10:54 AM

Hi,

I resume this old post since I have a situation very similar to the one described by DImitiri earlier.

I reuse his sample code.

I've seen that "Binding_Parse" is not fired the first time I select another item in the DropDownList, while all the other times it is correctly executed.

I also set an "OnSelectedValueChanged" event on the combobox and I see that the parameters newValue and oldValue are always correct, even the first time.

Is this a known issue? Or is there a way to force the Binding when OnSelectedValueChanged is raised?

Thanks

namespace TestDDL
{
  public partial class Form1 : RadForm
  {
    private List<Supplier> supplierList;
 
    public Form1()
    {
      InitializeComponent();
 
      suplierList = new List<Supplier>();
      suplierList.Add(new Supplier(1, "(1) Exotic Liquids"));
      suplierList.Add(new Supplier(2, "(2) New Orleans Cajun Delights"));
      suplierList.Add(new Supplier(3, "(3) Tokyo Traders"));
      suplierList.Add(new Supplier(4, "(4) Norske Meierier"));
      suplierList.Add(new Supplier(5, "(5) New England Seafood Cannery"));
      suplierList.Add(new Supplier(6, "(6) Leka Trading"));
 
      // I create the record here to be displayed in the RadDataEntry form
      var record = new Record();
      record.SupplierItem = 3;  // I want the drop down list to initially display item 3 or 'Tokyo Traders'
                                // This is what is not working ...
 
      radDataEntry1.DataSource = record;
    }
 
    void radDataEntry1_EditorInitializing(object sender, Telerik.WinControls.UI.EditorInitializingEventArgs e)
    {
      if (e.Property.Name == "SupplierItem")
      {
        var radDropDownList1 = new RadDropDownList();
 
        radDropDownList1.DataSource = suplierList;
 
        radDropDownList1.ValueMember = "SupplierID";
        radDropDownList1.DisplayMember = "CompanyName";
       radDropDownList1.Parent = this;
        e.Editor = radDropDownList1;
      }
    }
 
    void radDataEntry1_BindingCreating(object sender, Telerik.WinControls.UI.BindingCreatingEventArgs e)
    {
      if (e.DataMember == "SupplierItem")
      {
        e.PropertyName = "SelectedValue";
      }
    }
 
    void radDataEntry1_BindingCreated(object sender, BindingCreatedEventArgs e)
    {
      if (e.DataMember == "SupplierItem")
      {
        e.Binding.FormattingEnabled = true;
        e.Binding.Parse += new ConvertEventHandler(Binding_Parse);
      }
    }
 
    private void Binding_Parse(object sender, ConvertEventArgs e)
    {
      int tmpvalue;
      int? result = int.TryParse(e.Value.ToString(), out tmpvalue) ? tmpvalue : (int?)null;
 
      e.Value = result;
    }
  }
 
  public class Record
  {
    public int SupplierItem { get; set; }
  }
 
  public partial class Supplier
  {
    private int? _supplierID;
    private string _companyName;
 
    public Supplier(int? supplierID, string companyName)
    {
        this._supplierID = supplierID;
        this._companyName = companyName;
    }
 
    public int? SupplierID
    {
        get
        {
            return this._supplierID;
        }
        set
        {
            this._supplierID = value;
        }
    }
 
    public string CompanyName
    {
        get
        {
            return this._companyName;
        }
        set
        {
            this._companyName = value;
        }
    }
  }
}
0
Andrea
Top achievements
Rank 1
answered on 10 May 2018, 10:56 AM
(Sorry, I forgot to modify this in the code : the datasource is loaded later, not during the initialization phase)
0
Andrea
Top achievements
Rank 1
answered on 10 May 2018, 11:33 AM

Oh, sorry, I'm wrong.

And I need to add an info.

I need to check for validation every time the selected item in the combo is changed.

So I added this at the end of the Binding_Parse function:

Validate(true);

 

That raise the DataEntry_ItemValidated event which, for now, only prints the selected value of the combo on a label for testing.

The Binding.event is raised, but when on the following DataEntry_ItemValidated the ItemValidatedEventArgs contains an old DataSource, still containing the old value.

 

Is there a way to get the actual value? Or is there a better way to force the validation without having to manually move the focus out of the dropDownList ?

 

Thanks!

0
Andrea
Top achievements
Rank 1
answered on 10 May 2018, 11:41 AM

By the way, if I set the following event on a TextBox, the ItemValidatedEventArgs has the correct values. 

private void ControlOnTextChanged(object sender, EventArgs eventArgs)
{
     Validate(true);
}
0
Andrea
Top achievements
Rank 1
answered on 10 May 2018, 11:48 AM

After this long monologue, I write the solution  :)

The Validate function must be called after the binding is completed, and luckily there's an evet for that:

private void Binding_BindingComplete(object sender, BindingCompleteEventArgs e)
{
    Validate(true);
}
0
Dimitar
Telerik team
answered on 11 May 2018, 09:54 AM
Hi Valerio,

I am glad that you have found a solution for this case. Do not hesitate to contact us if you have any other questions.
 
Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Michael
Top achievements
Rank 1
Iron
answered on 12 Aug 2021, 11:21 PM

I just had the same problem- most dropdowns were working OK except for one.  Was driving me nuts!  I set the parent, stopped resetting the datasource for every update, loaded the datasource once in the form's .Load event.

I noticed that the ones that were working had a SQL lookup value of INT.  The finicky one was BIGINT.  So I switched the datatype to INT in the database and bam it started working.

It's always something.  I'm just glad I fixed this bug.  That took (unbillable) hours.

 

Tags
DropDownList
Asked by
DBA
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Michael Hildebrand
Top achievements
Rank 2
Andrea
Top achievements
Rank 1
Michael
Top achievements
Rank 1
Iron
Share this question
or