Updating Folders name after ItemDraggingEventArgs

Hello i am trying since 3 days without succes...
I have a listview with 3 folders, after ItemDraggingEventArgs i would like to update the folders name to folder+index of the listview.
Row 0 -> folder0       Row1->folder1   ...

It s working only 1 time after bug ->

Can u help me plz?





1 Reply 1 reply marked as answer

LN Lakshmi Natarajan Syncfusion Team November 10, 2020 09:57 AM UTC

Hi Ludo, 
 
Thank you for using Syncfusion products. 
 
We have checked the reported query “Updating Folders name after ItemDraggingEventArgs” from our side. We would like to inform you that you can achieve your requirement by using the DragDropController.UpdateSource as True, which updates the underlying collection after drag and drop by default. Please refer the following user guidance document regarding the same, 
 
Please refer the following code snippets to achieve your requirement, 
XAML: Define converter to display the group name with index. 
<syncfusion:SfListView x:Name="ToDoListView" 
                               ItemSize="60" 
                               IsStickyHeader="True" 
                               ItemsSource="{Binding ToDoList}" 
                               DragStartMode="OnHold,OnDragIndicator" 
                               SelectionMode="None"> 
            <syncfusion:SfListView.DragDropController> 
                <syncfusion:DragDropController UpdateSource="True"/> 
            </syncfusion:SfListView.DragDropController> 
            ... 
            <syncfusion:SfListView.ItemTemplate> 
                <DataTemplate> 
                        <Grid> 
                            ... 
                            <Label Text="{Binding ., Converter={StaticResource indexConverter}, ConverterParameter={x:Reference ToDoListView}}" Grid.Column="1" Margin="5,3,0,0" VerticalOptions="Center" HorizontalOptions="Start" /> 
                            ... 
                        </Grid> 
                </DataTemplate> 
            </syncfusion:SfListView.ItemTemplate>  
</syncfusion:SfListView> 
 
Converter: You can get the group items from the GroupResult using reflection. Return the GroupResult.Key  with index. 
public class IndexConverter : IValueConverter 
{ 
    SfListView ListView; 
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
    { 
        if (value == null) return 0; 
 
        var item = value as ToDoItem; 
        ListView = parameter as SfListView; 
 
        var groupresult = GetGroup(item);    
        var dropGroupList = groupresult.GetType().GetRuntimeProperties().FirstOrDefault(method => method.Name == "ItemList").GetValue(groupresult) as List<object>; 
        return groupresult.Key.ToString() + " " + dropGroupList.IndexOf(item); 
    } 
 
    private GroupResult GetGroup(object itemData) 
    { 
        GroupResult itemGroup = null; 
 
        foreach (var item in this.ListView.DataSource.DisplayItems) 
        { 
            if (item == itemData) 
                break; 
 
            if (item is GroupResult) 
                itemGroup = item as GroupResult; 
        } 
        return itemGroup; 
    } 
} 
 
C#: Refresh the ListViewItems to reflect the changes in the UI using RefreshListViewItem method. 
public class Behavior : Behavior<ContentPage> 
{ 
    SfListView ListView; 
 
    protected override void OnAttachedTo(ContentPage bindable) 
    { 
        ListView = bindable.FindByName<SfListView>("ToDoListView"); 
        ListView.ItemDragging += ListView_ItemDragging; 
        base.OnAttachedTo(bindable); 
    } 
 
    private void ListView_ItemDragging(object sender, ItemDraggingEventArgs e) 
    { 
        if (e.Action == DragAction.Drop) 
        { 
            Device.BeginInvokeOnMainThread(() => ListView.RefreshListViewItem(-1, -1, true)); 
        } 
    } 
} 
 
We have prepared a sample based on your requirement and you can download it using the following link, 
 
Please let us know if this helps. 
 
Lakshmi Natarajan 
 


Marked as answer
Loader.
Up arrow icon