Introduction
This article demonstrates how to create Dynamic GridView using Xamarin.Forms. If you ever need to show something in a data-bound grid view that is not in your data source, just create that extra row dynamically.
Dynamic GridView
Dynamic GridView is a ViewGroup that displays items in a two-dimensional, scrollable grid. The grid items are automatically inserted into the layout using a ListAdapter. This GridView will fill the entire screen. The attributes are rather self-explanatory. For more information about valid attributes, see the GridView reference.

Let's start
Step 1
Create a Xamarin.Forms app by going to File >> New >> Visual C# >> Cross Platform >> Cross platform app (Xamarin.Native or Xamarin.Forms) and click OK. Project Name :DynamicGrid

Now, select Blank App >> Xamarin.Forms >> .Portable Class Library and click OK.
Step 2
After the project creation, add the following Nuget Packages for your projects. Open Solution Explorer >> right click to solution explorer and select "Manage NuGet packages for the solution".
Now, select the following NuGet packages and followed by select your project then click to Install it.
This article demonstrates how to create Dynamic GridView using Xamarin.Forms. If you ever need to show something in a data-bound grid view that is not in your data source, just create that extra row dynamically.
Dynamic GridView
Dynamic GridView is a ViewGroup that displays items in a two-dimensional, scrollable grid. The grid items are automatically inserted into the layout using a ListAdapter. This GridView will fill the entire screen. The attributes are rather self-explanatory. For more information about valid attributes, see the GridView reference.

Let's start
Step 1
Create a Xamarin.Forms app by going to File >> New >> Visual C# >> Cross Platform >> Cross platform app (Xamarin.Native or Xamarin.Forms) and click OK. Project Name :DynamicGrid

Now, select Blank App >> Xamarin.Forms >> .Portable Class Library and click OK.
Step 2
After the project creation, add the following Nuget Packages for your projects. Open Solution Explorer >> right click to solution explorer and select "Manage NuGet packages for the solution".
Now, select the following NuGet packages and followed by select your project then click to Install it.
- Xamarin.Forms update 2.5.0.121934.

Step 3
Next, open Solution Explorer >> Project Name(Portable) >> Right click to add >> New iteam . After that, open the Dialog Box Select Xamarin.Forms >> ContentPage and click ok (Page Name: DynamicGridpage ).

Step 4
Next, open Solution Explorer >> Project Name(Portable) >> DynamicGridPage.xaml. After that, open the Design View of this page. Just replace that the following code.
Grid View Name: gridLayout

Xaml Code
- <?xml version="1.0" encoding="utf-8"?>
- <ContentPage
- xmlns="http://xamarin.com/schemas/2014/forms"
- xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
- xmlns:local="clr-namespace:DynamicGrid"
- x:Class="DynamicGrid.DynamicGridPage">
- <Grid x:Name="gridLayout"></Grid>
- </ContentPage>
Next, open Solution Explorer >> Project Name(Portable) >> DynamicGridPage.xaml >> DynamicGridPage.cs. After that, open the backend View of this page. Just replace that the following code.

14 line to 19 line Create an ArrayList and add product values, 21 to 25 line Define rows and columns.
Looping
C# for loop: The for keyword indicates a loop in C#. The for loop executes a block of statements repeatedly until the specified condition returns false. As per the syntax above, the for loop contains three parts: initialization, conditional expression, and steps, which are separated by a semicolon


14 line to 19 line Create an ArrayList and add product values, 21 to 25 line Define rows and columns.
Looping
C# for loop: The for keyword indicates a loop in C#. The for loop executes a block of statements repeatedly until the specified condition returns false. As per the syntax above, the for loop contains three parts: initialization, conditional expression, and steps, which are separated by a semicolon



meir rotfPosted Apr 22, 2020, 4:19 AM
Hi I tried to add the dynamicgrid page to an exisiting project. on the gridlayout lines i get error type or namespace not found AnySuggestions?
Wei Chun LaiPosted Oct 10, 2018, 12:12 AM
This predefined the row and column , is that possible to add list of dynamic item to it and the row and column also dynamic ?
sabu balakrishnanPosted Sep 22, 2018, 3:41 PM
How do i identify item click
Kristian PospišPosted Apr 27, 2018, 10:45 AM
Dont forget to add Product.cs if it doesn't work right away. You can add before the line private List<Product> . This " internal class Product { public string Name { get; set; } } " inside xaml.cs and it should work. https://pospisk.me/