19 Answers, 1 is accepted
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.
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.
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.
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
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;
}
}
}
}
Sorry misspelt 'supplierList', just change:
private List<Supplier> supplierList;
to
private List<Supplier> suplierList;
:) Less changes :)
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
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.
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.
Dimitar
Telerik
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
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
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
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.
Dimitar
Telerik
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;
}
}
}
}
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!
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
);
}
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
);
}
I am glad that you have found a solution for this case. Do not hesitate to contact us if you have any other questions.
Dimitar
Progress Telerik
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.