Articles in this section
Category / Section

How to load SfDataGrid inside a Fragment?

1 min read

SfDataGrid can be loaded inside a Fragment by customizing the Fragment class and returning the grid in the OnCreateView override of the Fragment class.

Refer the below code example in which a FrameLayout containing SfDataGrid is added inside a fragment.

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
                        android:id="@+id/frameLayout"
                        android:layout_weight="1"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent" />

 

public class CustomFragment:Fragment
    {
        SfDataGrid sfDataGrid;
 
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            base.OnCreateView(inflater, container, savedInstanceState);
            var view = inflater.Inflate(Resource.Layout.Main, container, false);
            FrameLayout layout =view.FindViewById<FrameLayout> (Resource.Id.frameLayout);
            layout.AddView(sfDataGrid);
            return view;
        }
    }

 

Refer the below code example in which the custom fragment containing SfDataGrid is created and added in the MainActivity using FragmentManager.

protected override void OnCreate(Bundle bundle)
{
    base.OnCreate(bundle);
 
    // Set our view from the "main" layout resource
    SetContentView (Resource.Layout.Main);
    var newFragment = new CustomFragment(BaseContext);
    var fragment = FragmentManager.BeginTransaction();
    fragment.Add(Resource.Id.frameLayout, newFragment);
    fragment.Commit();
}

 

Screenshot

C:\Users\pavithra.sivakumar\AppData\Local\Microsoft\Windows\INetCacheContent.Word\Screenshot_2017-01-25-12-14-12.png

 

Sample Link

How to load SfDataGrid inside a Fragment?

 

Conclusion

I hope you enjoyed learning about how to load SfDataGrid inside a Fragment.

You can refer to our Xamarin.Android DataGrid feature tour page to know about its other groundbreaking feature representations. You can also explore our Xamarin.Android DataGrid documentation to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied