Moving Items Between Groups

The way this control works with ID is confusing. It seems to include groups in the indexes with is very odd.

Anyway, I'm trying to move items between groups like this:

private void MoveItemToNewGroup(List<object> from, List<object> to, object item, int insertAt)
{
    from.Remove(item);
    to.Insert(insertAt, item);
}


Any ideas how this might work properly? Is there a better way to move things between groups?

It seems the rendering doesn't work properly using the method above. The moved item sometimes isn't the correct height and sometimes subsequently touching a drag indicator then crashes the application.  Also the header of the group the item is moved to expands to a much greater height than it should be as set by the GroupHeaderSize property.

Once this code has executed I'm updating the view like this:

private void _viewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
    if (e.PropertyName == nameof(_viewModel.PrioritisedTasks))
    {
        var vis = TodoListView.GetVisualContainer();

        vis.ForceLayout();
    }
}

The stack trace is:

"<unnamed thread>"  at (wrapper stelemref) object.virt_stelemref_object (intptr,object) [0x00008] in <5e602907309a47679d31716bdfe8432e>:0
  at System.Collections.Generic.List`1<T_REF>.Insert (int,T_REF) [0x00056] in /Users/builder/jenkins/workspace/archive-mono/2019-10/android/release/external/corefx/src/Common/src/CoreLib/System/Collections/Generic/List.cs:695
  at System.Collections.ObjectModel.Collection`1<T_REF>.InsertItem (int,T_REF) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2019-10/android/release/external/corefx/src/Common/src/CoreLib/System/Collections/ObjectModel/Collection.cs:154
  at System.Collections.ObjectModel.ObservableCollection`1<T_REF>.InsertItem (int,T_REF) [0x00006] in /Users/builder/jenkins/workspace/archive-mono/2019-10/android/release/external/corefx/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs:192
  at System.Collections.ObjectModel.Collection`1<T_REF>.Add (T_REF) [0x00020] in /Users/builder/jenkins/workspace/archive-mono/2019-10/
android/release/external/corefx/src/Common/src/CoreLib/System/Collections/ObjectModel/Collection.cs:71
  at Syncfusion.DataSource.Extensions.FunctionalExtensions.ToObservableCollection<T_REF> (System.Collections.Generic.IEnumerable`1<T_REF>) [0x00018] in <68dcf5c2a3ba44cdbff731420b8fba3e>:0
  at Syncfusion.ListView.XForms.DragDropController.ProcessDragStarted (Syncfusion.ListView.XForms.ListViewItemInfoBase,Xamarin.Forms.Point,Xamarin.Forms.Point) [0x000bb] in <090dc9d2df434862873423c6924b00d8>:0
  at Syncfusion.ListView.XForms.DragDropController.HandleTouchInteractions (Syncfusion.ListView.XForms.ListViewItemInfoBase,Xamarin.Forms.GestureStatus,Xamarin.Forms.Point,Xamarin.Forms.Point) [0x000c8] in <090dc9d2df434862873423c6924b00d8>:0
  at Syncfusion.ListView.XForms.Android.DragIndicatorViewRenderer.OnInterceptTouchEvent (Android.Views.MotionEvent) [0x00084] in <2dea30e85e3b4b60bec087ac83afdb64>:0
  at Android.Views.ViewGroup.n_OnInterceptTouchEvent_Landroid_view_MotionEvent_ (intptr,intptr,intptr) [0x00013]

3 Replies

LN Lakshmi Natarajan Syncfusion Team May 18, 2020 01:03 PM UTC

Hi James, 
 
Thank you for using Syncfusion products. 
 
We have checked the reported query “Moving items between groups” from our end. We would like to suggest you to use the DragAndDrop feature of SfListView to rearrange the items. The reordered collection will be reflected to the ListView collection by enabling UpdateSource as True for DragDropController. You can also move the items between groups of SfListView. 
 
Please refer our online user guidance document for your reference, 
UG link: 
 
Please let us know if you need further assistance. 
 
Regards, 
Lakshmi Natarajan 
 



JG James Green May 18, 2020 02:31 PM UTC

I don't think you read my question properly

I'm trying to move things between groups programmatically.

For instance, changing the value for an items GroupName in this instance doesn't change the items group in the UI.  It stays in the same group even though the value for GroupName has been changed.

<blockquote><syncfusion:sflistview.datasource>
    <syncfusiondata:datasource>:GroupDescriptor PropertyName="GroupName"/>
        <syncfusiondata:datasource.groupdescriptors>
            <syncfusiondata:groupdescriptor propertyname="GroupName"></syncfusiondata:groupdescriptor>
        </syncfusiondata:datasource.groupdescriptors>
    </syncfusiondata:datasource>
</syncfusion:sflistview.datasource>

<blockquote>

<syncfusion:sflistview.datasource>
    <syncfusiondata:datasource>
        <syncfusiondata:datasource.groupdescriptors>
            <syncfusiondata:groupdescriptor propertyname="GroupName"><syncfusiondata:groupdescriptor>
        <syncfusiondata:datasource.groupdescriptors>
    <syncfusiondata:datasource>
<syncfusion:sflistview.datasource>



LN Lakshmi Natarajan Syncfusion Team May 19, 2020 11:03 AM UTC

Hi James, 
 
Sorry for the inconvenience caused. 
 
We have checked the reported query “How to move the items between Group” from our end. We would like to inform you that you can notify the property change to the DataSource by using LiveDataUpdateMode as AllowDataShaping property of DataSource. In this case, the ListView will be refreshed based on the Group PropertyName and update at the last index of the particular group. If you want to move the item at the particular index of the list, you can use Move method of the ViewModel collection. Please refer the following code snippet for your reference, 
 
Xaml: 
<syncfusion:SfListView x:Name="listView" Grid.Row="1" ItemSize="60" BackgroundColor="#FFE8E8EC" GroupHeaderSize="50" ItemsSource="{Binding ToDoList}" DragStartMode="OnDragIndicator" SelectionMode="None"> 
            <syncfusion:SfListView.DataSource> 
                <data:DataSource LiveDataUpdateMode="AllowDataShaping"> 
                    <data:DataSource.GroupDescriptors> 
                        <data:GroupDescriptor PropertyName="CategoryName" /> 
                    </data:DataSource.GroupDescriptors> 
                </data:DataSource> 
            </syncfusion:SfListView.DataSource> 
... 
 
 
Code behind: 
private void HeaderLabel_Clicked(object sender, EventArgs e) 
{ 
    viewModel.ToDoList[4].CategoryName = "This Week"; 
    viewModel.ToDoList.Move(4, 1); 
} 
 
 
We have attached the tested sample in the following link, 
 
You can also refer our user guidance document to regarding LiveDataUpdateMode from the following link, 
 
Please let us know if you need further assistance. 
 
Regards, 
Lakshmi Nataraja 


Loader.
Up arrow icon