I'm looking into the ItemReorder funktionality within the DataBoundListBox
I need a way to control if the item can be reordered or not. Is there an event or command when an item is about to be reordered or any other way to disable the reordering for a specific item in the ListBox?
I also need a way to hook up an event when the reordering is done e.g. when the reorder buttons is closed.
Regards
>> Jonas
5 Answers, 1 is accepted
Thank you for contacting us. Currently, we don't have a straightforward way to achieve you scenario. But with few additional lines it can be achieved to a certain degree.
Let's assume the DataBoundListBox control is bound to a list of integers:
List<
int
> numbers =
new
List<
int
>(Enumerable.Range(0, 10));
this
.dataBountListBox1.ItemsSource = numbers;
For the sake of the example, let's say we want to be able to reorder only odd numbers. To do that, we'll have to listen for the Hold event of the DataBoundListBox control:
<
telerikPrimitives:RadDataBoundListBox
x:Name
=
"dataBountListBox1"
Hold
=
"DataBountListBox_Hold"
>
<
telerikPrimitives:RadDataBoundListBox.ItemTemplate
>
<
DataTemplate
>
<
Grid
Margin
=
"5"
Background
=
"LightGray"
>
<
TextBlock
VerticalAlignment
=
"Center"
Text
=
"{Binding}"
FontSize
=
"32"
Foreground
=
"Black"
Margin
=
"0 5"
/>
</
Grid
>
</
DataTemplate
>
</
telerikPrimitives:RadDataBoundListBox.ItemTemplate
>
</
telerikPrimitives:RadDataBoundListBox
>
In the event handler, simple get a reference to the DataBoundListBoxItem we've been holding and based on its DataContext, determine whether reordering should be allowed or not:
private
void
DataBountListBox_Hold(
object
sender, System.Windows.Input.GestureEventArgs e)
{
// get an instance of the DataBoundListBoxItem
RadDataBoundListBoxItem item = ElementTreeHelper.FindVisualAncestor<RadDataBoundListBoxItem>(e.OriginalSource
as
DependencyObject);
// for testing purposes allow reordering only of odd numbers
int
number = (
int
)item.DataContext;
if
(number % 2 != 0)
{
this
.dataBountListBox1.ActivateItemReorderForItem(item);
}
}
However, we still don't have a mechanism which notifies you once reorder has been completed.
Give this approach a try and let me know if it works for you.
I'd be glad to assist you further.
Greetings,
Kiril Stanoev
the Telerik team
I have a further/related question for this: How can I know when user has finished reordering (when the reorder buttons have disappeared). Need to hook up to this kind of event to be able to save the updated order into cloud service. Or is there an another/better way to accomplish the same results?
Thanks for writing.
There is not currently a straightforward way to know this. We can expose an event that informs you about these state changes in Q3 2013 SP1 timeframe (in a month or so). Let us know if this is alright with you?
Regards,
Deyan
Telerik
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Thanks Deyan,
This will do fine. Meanwhile I can use a timer-based approach, which is dirty and unsecure, but works in most cases. If user exits the app before timer has launched the saving of the data, changes are lost. Also, polling the isDirty with a timer possibly unnecessarily consumes battery of the device. Since there is currently no way of knowing when the user has finished editing, the save timer can launch the saving even if user is still modifying the list.
As soons as the new event is exposed, I will start using it. It will provide a much simpler and cleaner approach to saving the updated data. :-)
Thanks for writing back.
We will be releasing an Internal Build containing the latest bits, the aforementioned event included. You will be able to download the IB from our website.
Stay tuned.
We will consider this thread closed for now. Let us know if you have further questions.
Regards,
Deyan
Telerik
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>