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

2010 Q3: DropDownList RadListDataItem Binding Bug?

11 Answers 205 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Rafael
Top achievements
Rank 1
Rafael asked on 14 Nov 2010, 07:21 PM
Hi!

I was using Q2, 2 dropdownlists with prices binded to it and it worked fine:

RadListDataItem rcbi0 = new RadListDataItem("ANY");
RadListDataItem rcbi1 = new RadListDataItem("1");
RadListDataItem rcbi2 = new RadListDataItem("10");
RadListDataItem rcbi3 = new RadListDataItem("15");
RadListDataItem rcbi4 = new RadListDataItem("20");
RadListDataItem rcbi5 = new RadListDataItem("25");
RadListDataItem rcbi6 = new RadListDataItem("30");
RadListDataItem rcbi7 = new RadListDataItem("40");
 
radDropDownListPriceMin.Items.AddRange(new[]{ rcbi0, rcbi1, rcbi2, rcbi3, rcbi4, rcbi5, rcbi6, rcbi7});
radDropDownListPriceMin.SelectedIndex = 0;
radDropDownListPriceMax.Items.AddRange(new[]{rcbi0, rcbi1, rcbi2, rcbi3, rcbi4, rcbi5, rcbi6, rcbi7});
radDropDownListPriceMax.SelectedIndex = 0;

Now , the same above code but with Q3, binds the RadListDataItems to radDropDownListPriceMax BUT radDropDownListPriceMin is empty!

This code works fine in Q3:

string[] pricesList = new string[7];
pricesList[0] = "ANY";
pricesList[1] = "1";
pricesList[2] = "10";
pricesList[3] = "15";
pricesList[4] = "20";
pricesList[5] = "25";
pricesList[6] = "30";
 
radDropDownListPriceMin.Items.AddRange(pricesList);
radDropDownListPriceMin.SelectedIndex = 0;
 
radDropDownListPriceMax.Items.AddRange(pricesList);
radDropDownListPriceMax.SelectedIndex = 0;

How come?

Rafael

11 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 14 Nov 2010, 09:04 PM
Hello,

this is curious. I can replicate your problem and it also happens with RadListControl too. The list of RadListDataItems only gets applied to the last control it was given too, and the previous controls have the list cleared (the item count is 0).

I'll have a look into this and see if I can come up with a workaround.

Richard
0
Rafael
Top achievements
Rank 1
answered on 14 Nov 2010, 09:09 PM
If this is a real bug in Q2 -> Q3 tehn the workaround will be a "night build" ;)
Hopefully for me, using the array is fine..
0
Richard Slade
Top achievements
Rank 2
answered on 14 Nov 2010, 09:12 PM
Hi Rafael,

Well, I certainly think it's a bug. You could also assign the RadListDataItems to a List<> and use it as a datasource. This also doesn't have any issues with it clearing the list of items, but I'll continue to look at this for you.

Richard
0
Richard Slade
Top achievements
Rank 2
answered on 14 Nov 2010, 09:20 PM
Looking into the class structure using reflector, I see that when one performs an AddRange(string) it is creating new RadListDataItems and then calling AddRange(RadListDataItem) which is what you are doing anyway in your sample.

Hopefully, I'll have more news for you shortly.
Richard
0
Richard Slade
Top achievements
Rank 2
answered on 14 Nov 2010, 10:33 PM
Hi,

I've figured out the issue I think, but this will need to be fixed by Telerik and for the moment, you should cotinue to use your other method of getting the items into the RadDropDownList, or create a List<> which can be used as a datasource.

I believe that the issue lies internally to the way that the RadDropdownList is adding the items when calling AddRange. Internally, it is calling the Add method which is setting the owner of the RadListDataItem to the new control. If you actually take the code that it is using and run it..
// User code
RadListDataItem rcbi0 = new RadListDataItem("ANY");
RadListDataItem rcbi1 = new RadListDataItem("1");
RadListDataItem rcbi2 = new RadListDataItem("10");
RadListDataItem rcbi3 = new RadListDataItem("15");
RadListDataItem rcbi4 = new RadListDataItem("20");
RadListDataItem rcbi5 = new RadListDataItem("25");
RadListDataItem rcbi6 = new RadListDataItem("30");
RadListDataItem rcbi7 = new RadListDataItem("40");
   
  
List<RadListDataItem> items = new List<RadListDataItem>();
items.Add(rcbi0);
items.Add(rcbi1);
items.Add(rcbi2);
items.Add(rcbi3);
items.Add(rcbi4);
items.Add(rcbi5);
items.Add(rcbi6);
items.Add(rcbi7);
// spoof Telerik Code
List<RadListDataItem> changedItems = new List<RadListDataItem>(items);
foreach (RadListDataItem item in changedItems)
{
radDropDownListPriceMin.Items.Add(item);
}
List<RadListDataItem> changedItems2 = new List<RadListDataItem>(items);
foreach (RadListDataItem item in changedItems2)
{
    radDropDownListPriceMax.Items.Add(item);
}
 then you can actually see the items being taken away one-by-one from the first RadDropDownList.

I beleive that this is because in the Add method, the owner is being changed for that RadDataListItem from one RadDropDownList control, to the other.

Best regards,

Richard


EDIT: Of course, ths also means that there will be a bug with the Add method when adding a RadListDataItem.
Richard
0
Emanuel Varga
Top achievements
Rank 1
answered on 16 Nov 2010, 09:56 AM
Hello,

In my opinion this is not a bug, you don't need to create list items to add to the dropdown, you can just create strings and add them like in the following example.
var rcbi0 = "ANY";
var rcbi1 = "1";
var rcbi2 = "10";
var rcbi3 = "15";
var rcbi4 = "20";
var rcbi5 = "25";
var rcbi6 = "30";
var rcbi7 = "40";
  
radDropDownListPriceMin.Items.AddRange(new[]{ rcbi0, rcbi1, rcbi2, rcbi3, rcbi4, rcbi5, rcbi6, rcbi7});
radDropDownListPriceMin.SelectedIndex = 0;
radDropDownListPriceMax.Items.AddRange(new[]{rcbi0, rcbi1, rcbi2, rcbi3, rcbi4, rcbi5, rcbi6, rcbi7});
radDropDownListPriceMax.SelectedIndex = 0;

And this is because, like Richard suggested, the Owner and the OwnerControl is changing when you assign the RadListDataItem from one dropdown to the other.

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
Telerik WinForms MVP
0
Richard Slade
Top achievements
Rank 2
answered on 16 Nov 2010, 10:03 AM
Hi Emanuel,

I don't agree that this isn't a bug, or at best not well implemented. A developer expects to be able to assign a datasource to more than one control. I don't see why using AddRange or Add should be different.

All the best
Richard
0
Emanuel Varga
Top achievements
Rank 1
answered on 16 Nov 2010, 10:46 AM
Then create a data source don't create items, an item can have just one owner and it could cause some very big problems if it were to allow you to assign the same item to two different controls.

What about if you have 2 or more dynamically created dropdowns connected to the same SelectedItem / SelectedValue changed event, you could want to check the OwnerControl of the item to get the sender dropdown, then what would you do? Guess?

If you want to use data binding, then please use data binding, if you want to use them in unbound mode please create items for each of the dropdowns.

And there is no difference between using Add and AddRange, it is just the way you are using it, if you take a closer look at the original post you will see that Rafael defined a list of strings which he was adding using AddRange, not a list of RadListDataItems.

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
Telerik WinForms MVP
0
Richard Slade
Top achievements
Rank 2
answered on 16 Nov 2010, 11:01 AM
Hi Emanuel,

I'm just trying to help answer the question as to why this was happening. I had actually read the original post and it stated that it used to be working with the same list bound to the two lists. It no longer worked this way in Q3.

For information, there are some differences between using Add and AddRange, but this is mainly in the events that are raised internally. My use of Add Vs AddRange in the code sample was simply to demonstrate to the OP that the items were being removed from the first list as they were added to the second.

regards,

Richard

0
Emanuel Varga
Top achievements
Rank 1
answered on 16 Nov 2010, 12:10 PM
Hello again,

Again i have to mention we are just talking about the current situation, if you really want me to give all the possible details available i can copy paste tons of documentation here, but i believe in giving the OP just the answer to his question, this way it is easier for him to follow and for us to offer just the right answer.

In the current case it is just a question of displaying items, not performance considerations, so i believe that in this case (and in the current threads purpose) it does not make any difference between adding items with AddRange and Add.

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
Telerik WinForms MVP
0
Richard Slade
Top achievements
Rank 2
answered on 16 Nov 2010, 12:18 PM
Hi Emanuel,
I agree. Which is why I just let him know why it was happening. It would be an interesting debate to continue, but offline so as not to fill this thread with information that is not required. If you wish to contact me at any point, I'd be really happy to hear from you. richard.slade @ (my company domain in my profile)

All the best
Richard

Rafael,
I hope this discussion has answered your questions and provided some interesting points. If you need more information, just let me know, and may I ask you to mark any answers that you feel have helped so others can find the answer quickly too.

Best wishes
Richard
Tags
DropDownList
Asked by
Rafael
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Rafael
Top achievements
Rank 1
Emanuel Varga
Top achievements
Rank 1
Share this question
or