Alex Lawson
Top achievements
Rank 1
Alex Lawson
asked on 20 Jul 2009, 11:36 AM
I have upgraded a listbox to the new verison, looks good but there is an issue with the selected flag.
Scenario: The list box has 2 items (a & b). I have selected item a via a mouse click and clicked the transfer button, then run the following code:
However when I debug the loop the first iteration (item a) passes the selection check, but the listitem.text and listitem.value are from item b.
I will attempt to code this another way for the moment, thought you would want to be aware.
Thanks,
Lee
Scenario: The list box has 2 items (a & b). I have selected item a via a mouse click and clicked the transfer button, then run the following code:
protected void lbxAssigned_Transferred(object sender, RadListBoxTransferredEventArgs e) |
{ |
foreach (RadListBoxItem listItem in lbxAvailable.Items) |
{ |
if (listItem.Selected) |
{ |
ProductCarriers objPC = new ProductCarriers(); |
string test = listItem.Text; |
objPC.Allocate(Convert.ToInt32(listItem.Value), Convert.ToInt32(cbxProducts.SelectedValue)); |
} |
} |
PopulateLists(); |
} |
However when I debug the loop the first iteration (item a) passes the selection check, but the listitem.text and listitem.value are from item b.
I will attempt to code this another way for the moment, thought you would want to be aware.
Thanks,
Lee
7 Answers, 1 is accepted
0
ManniAT
Top achievements
Rank 2
answered on 20 Jul 2009, 12:02 PM
Hi Alex,
to be sure that I understood what you explained.
You have 2 listboxe - the first has two items and is named lbAvailable - the second is named lbxAssigned.
So at the start it looks like this
lbAvailable lbxAssigned
a
b
After you transfer it looks like:
lbAvailable lbxAssigned
b a
Markup (I know you are databound) may look like this:
If this is correct - your code - and the RadListboxes work like they should!!
In your code which handles the transfer to lbxAssigned - you query what is in lbxAvailable.
And this is item B which gets selected after item I is transfered.
--(check in the samples or remove "autoupdate" temporarily) you will see that the "next item" is selected.
So what you get is what it is - you query item b from the first (lbAvailable) listbox.
Try to iterate through lbxAssigned - now you should get item a (not selected).
Regards
Manfred
to be sure that I understood what you explained.
You have 2 listboxe - the first has two items and is named lbAvailable - the second is named lbxAssigned.
So at the start it looks like this
lbAvailable lbxAssigned
a
b
After you transfer it looks like:
lbAvailable lbxAssigned
b a
Markup (I know you are databound) may look like this:
<telerik:RadListBox ID="lbAvailable" runat="server" AllowTransfer="true" TransferMode="Move" TransferToID="lbxAssigned" > |
<Items> |
<telerik:RadListBoxItem runat="server" Value="1" Text="a" /> |
<telerik:RadListBoxItem runat="server" Value="2" Text="b" /> |
</Items> |
</telerik:RadListBox> |
<telerik:RadListBox ID="lbxAssigned" runat="server" ontransferred="lbxAssigned_Transferred"> |
<Items> |
</Items> |
</telerik:RadListBox> |
In your code which handles the transfer to lbxAssigned - you query what is in lbxAvailable.
And this is item B which gets selected after item I is transfered.
--(check in the samples or remove "autoupdate" temporarily) you will see that the "next item" is selected.
So what you get is what it is - you query item b from the first (lbAvailable) listbox.
Try to iterate through lbxAssigned - now you should get item a (not selected).
Regards
Manfred
0
Alex Lawson
Top achievements
Rank 1
answered on 20 Jul 2009, 12:05 PM
Ah I see, thanks - evidentally I have picked the wrong event.
I would have expected to selected flag to be cleared after transferred has fired though :)
I would have expected to selected flag to be cleared after transferred has fired though :)
0
ManniAT
Top achievements
Rank 2
answered on 20 Jul 2009, 12:11 PM
Hi,
not the wrong event -- the wrong listbox.
foreach(.....in lbxAvailable)...
should be
foreach(.....in lbxAssigned)
And by the way (regarding to your sample) - b (or in general a newly transfered item) is NOT selected.
Cheers
Manfred
PS: If this solved your problem - please mark the post as answer.
not the wrong event -- the wrong listbox.
foreach(.....in lbxAvailable)...
should be
foreach(.....in lbxAssigned)
And by the way (regarding to your sample) - b (or in general a newly transfered item) is NOT selected.
Cheers
Manfred
PS: If this solved your problem - please mark the post as answer.
0
Alex Lawson
Top achievements
Rank 1
answered on 20 Jul 2009, 12:34 PM
No this is the correct listbox in the context of what the code is trying to achieve, this is legacy code I am trying to upgrade to the Telerik Listbox, unfortunatly the telerik listbox does not seem to behave as per the control set I am trying to replace therefore I will recode the whole thing.
Thanks,
Lee
Thanks,
Lee
0
Accepted
ManniAT
Top achievements
Rank 2
answered on 20 Jul 2009, 12:37 PM
Hi Lee,
sorry about that "wrong listbox" - since you didn't argue about my first post I thought my (assumed) code was fitting your situation.
Cheers
Manfred
sorry about that "wrong listbox" - since you didn't argue about my first post I thought my (assumed) code was fitting your situation.
Cheers
Manfred
0
Alex Lawson
Top achievements
Rank 1
answered on 20 Jul 2009, 12:51 PM
No problem, I have fixed my code by simply looping through the RadListBoxTransferredEventArgs.items instead. I hate legacy code but it has to be done.
Thanks for your help.
Thanks for your help.
0
ManniAT
Top achievements
Rank 2
answered on 20 Jul 2009, 01:02 PM
I hate legacy code too - but currently I have positive feelings about it.
My current project is to "rebuild" a .NET 1.x (yes ONE) datalist, datarepeater project to 3.5 with telerik controls.
Every phone call with my customer makes me happy :)
Oh great, so fast, so beautiful...oh, it automatically handles that error, aah, the page does not reload when i save...
My current project is to "rebuild" a .NET 1.x (yes ONE) datalist, datarepeater project to 3.5 with telerik controls.
Every phone call with my customer makes me happy :)
Oh great, so fast, so beautiful...oh, it automatically handles that error, aah, the page does not reload when i save...