We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Update item in group sflistview

How to update an item from a group in sflistview(MVVM)?

I can only update, only when I reload the ItemsSource.

Could you show an example?


3 Replies

SY Suthi Yuvaraj Syncfusion Team November 8, 2022 09:12 AM

To update the items of the ListView , you enable the INotifyPropertyChanged for each item in the Model class to update the UI when you update the items. Please refer the below documentation for more reference.


UG Link: https://help.syncfusion.com/maui/listview/getting-started#creating-data-model-for-the-listview


Also If you want to update the items of the groups in SfListView, set the listView.DataSource.LiveDataUpdateMode to LiveDataUpdateMode.AllowDataShaping, which updates the runtime changes in the groups.Please refer the below  ug for more information.


Grouping: https://help.syncfusion.com/maui/listview/grouping


Please let us know if you are facing the issue? If yes please share the exact requirement on updating the items of the Groups. Also we have attached the sample for Grouping and creating and binding the data to the listview.


Attachment: SimpleListView_MAUI_52cf0c13.zip


DF Davi Fabiano November 9, 2022 10:04 AM

Hi!


I made a change to the example they sent to demonstrate.

I added a button where the description changes on click but doesn't update!

Can you help me?




Attachment: SimpleListView_MAUI_338e0f3.zip


SY Suthi Yuvaraj Syncfusion Team November 10, 2022 08:26 PM

We have checked the provide sample, we would like let you that Button inside the GroupHeaderTemplate which have the binding context as the Group result , where the GroupResult contains Groups , Key , Items and IsExpand properties , as changes these properties will trigger the converter, which bound the binding context of the DataTrigger of button.Here you have achieve you requirement by setting the proper binding context and refreshing the datasource. we have attached the code snippet and modified sample for your reference and let us know if  you still facing issue.


Code snippet:

Xaml page

<syncfusion:SfListView.GroupHeaderTemplate >

<DataTemplate x:Name="GroupHeaderTemplate">

<Button Text="Collect"

TextTransform="None"

Command="{Binding Path=BindingContext.ButtonCollectCommand, Source={x:Reference collectionsPage}, Mode=TwoWay}"

CommandParameter="{Binding .}" 

Padding="0"

HeightRequest="34"

WidthRequest="120">

<Button.Triggers>

<DataTrigger TargetType="Button"

Binding="{Binding Path= BindingContext.Items,Source= {RelativeSource Self}, Converter={StaticResource ConverterCollecting}}"

Value="True">

<Setter Property="IsEnabled" Value="False"/>

<Setter Property="Text" Value="Collecting"/>

<Setter Property="BackgroundColor" Value="IndianRed"/>

</DataTrigger>

</Button.Triggers>


ViewModel.cs 

public Command ButtonCollectCommand => new Command<object>((x) => OnButtonCollectClick(x));

private void OnButtonCollectClick(object obj)

{

GroupResultSelected = obj as GroupResult;

var items = GroupResultSelected.Items.ToList<Model>().ToObservableCollection();

ExecuteCollectCommand(items).ConfigureAwait(true);

GetData.Refresh();

}

private async Task ExecuteCollectCommand(ObservableCollection<Model> pointview)

{

//Alternate True / False

pointview[0].Group.Collecting = !pointview[0].Group.Collecting;

}

}


Attachment: SimpleListView_MAUI_c4ec41c8.zip

Loader.
Live Chat Icon For mobile
Up arrow icon