refresh previous page (grid) on back button after new data inserted in a child.

Hello
I have got a problem with refreshing prev. page when back button pressed. On the first (Parent): I have a SfDataGrid (programmatically added) and the button "add new". On tapped event I'll navigate to Update page and when back to parent- I can see than row data is changed. From Parent (pressing "Add" button) I go to Create page and insert data. When I save data, I see that it was added to DB but navigating back to Parent shows that my grid was not refreshed.
Could you please help me. Any advice will be appreciated.

my Parent activity:
using System;
using Android.App;
using Android.OS;
using Android.Views;
using Android.Widget;
using MobiLEMS.Core.ViewModel;
using MobiLEMS.Droid.Views.Styles;
using MobiLEMS.DTO.Base;
using MvvmCross.Droid.Views;
using Syncfusion.Data;
using Syncfusion.GridCommon.ScrollAxis;
using Syncfusion.SfDataGrid;
using Android.Content;
using System.Collections.ObjectModel;

namespace MobiLEMS.Droid.Views
{
[Activity(MainLauncher = false, NoHistory = false, AlwaysRetainTaskState = true, LaunchMode = Android.Content.PM.LaunchMode.SingleTask, WindowSoftInputMode = SoftInput.StateAlwaysHidden)]
//
public class ParentView : MvxActivity
{
private SfDataGrid _dataGrid;

    protected override void OnDestroy()
    {
        base.OnDestroy();
        _dataGrid.GridTapped -= GridTapped;
    }

    [Android.Runtime.Register("onResume", "()V", "GetOnResumeHandler")]
    protected override void OnResume()
    {
        base.OnResume();
    }

    protected override void OnRestart()
    {
        base.OnRestart();
        Recreate();
    }


    protected override void OnCreate(Bundle bundle)
    {
        try
        {
            base.OnCreate(bundle);
            Title = MobiLEMS.Resources.Properties.Resources.StrTitle;
            var myLayoutView = (TableLayout)FindViewById(Resource.Id.TableLayout2);
            _dataGrid = new SfDataGrid(BaseContext);

            GridTextColumn Column1 = new GridTextColumn
            {
                MappingName = "CD",
                HeaderText = "CD
           };

            GridTextColumn 1Column2 = new GridTextColumn()
            {
                MappingName = "Qty",
                HeaderText = "Qty
            };

            _dataGrid = new SfDataGrid(BaseContext)
            {
                ItemsSource = ViewModel.DS,
                ColumnSizer = ColumnSizer.Star,
                GridStyle = new Dark(),
                AllowSwiping = false,
                SelectionMode = SelectionMode.Single,
                AutoGenerateColumns = false
            };
            _dataGrid.AutoGenerateColumnsMode = AutoGenerateColumnsMode.None;

            _dataGrid.Columns.Add(Column1);
            _dataGrid.Columns.Add(Column2);
            _dataGrid.GridTapped += GridTapped;
            myLayoutView.AddView(_dataGrid);
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
            throw;
        }
    }

public ObservableCollection LT { get; set; }
private void GridTapped(object sender, GridTappedEventArgs e)
{
var lt = e.RowData as LT;
if (lt != null)
{
ViewModel.UpdateViewModel(lt);
}
}

    public new ParentViewModel ViewModel
    {
        get { return (ParentViewModel)base.ViewModel; }
        set { base.ViewModel = value; }
    }

    protected override void OnViewModelSet()
    {
        base.OnViewModelSet();
        SetContentView(Resource.Layout. ParentView);
    }

}

}

Thank you!

Answers

  • MizanurRahman.0834MizanurRahman.0834 USMember ✭✭

    Use following line to refresh your Grid.

    yourAdapter.NotifyDataSetChanged();

  • eakhmetovaeakhmetova Member

    Hello. Sorry, I was not able to answer earlier. Im really a new Mobil developer. And I'm not sure where I should implement it. Any advise?
    Thanks a lot.

Sign In or Register to comment.