Articles in this section
Category / Section

How to insert other controls inside a GridCell in Xamarin.Android DataGrid?

3 mins read

SfDataGrid displays the values of the binded data objects in the GridCells. It allows you to insert any type of data and also to customize the views inserted in the GridCell. To customize the views inserted in the Gridcell, you have to create a template column and use a custom GridCell derived from the GridCell in the template column.

You can refer the following user documentation link for more details regarding usage of TemplateColumn.

Refer the following code example which illustrates how to insert a Syncfusion Chart control in the GridCells by using the template column and custom GridCell.

MainActivity.cs

GridTextColumn chartcell = new GridTextColumn();

                             chartcell.Width = 250;

                             chartcell.UserCellType = typeof(ChartCell);

                             chartcell.MappingName = "Transactions";

 

CustomCell.cs

public class ChartCell : GridCell
{
   SfChart chart;
 
   public ChartCell(Context ctxt):base(ctxt)
   {
      chart = new SfChart(ctxt);
      chart.Title.Text = "Transaction Rate";
 
      //Initializing Primary Axis
      CategoryAxis primaryAxis = new CategoryAxis();
      primaryAxis.Title.Text = "Year";
      chart.PrimaryAxis = primaryAxis;
 
      //Initializing Secondary Axis
      NumericalAxis secondaryAxis = new NumericalAxis();
      secondaryAxis.Title.Text = "Transactions";
      chart.SecondaryAxis = secondaryAxis;
      DataModel dataModel = new DataModel();
 
      //Adding ColumnSeries to the chart for Precipitation
      chart.Series.Add(new ColumnSeries()
      {
          DataSource = dataModel.chartData,
          YAxis = new NumericalAxis()
          {
              OpposedPosition = true,
              ShowMajorGridLines = false
          }
      });
      this.AddView(chart);
   }
 
   protected override void OnLayout(bool changed, int left, int top, int right, int bottom)
   {
      chart.Layout(0,0,this.Width,this.Height);
   }
 
   protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
   {
      base.OnMeasure(widthMeasureSpec, heightMeasureSpec);              
      chart.Measure(MeasureSpec.MakeMeasureSpec(widthMeasureSpec,MeasureSpecMode.Exactly),
                              MeasureSpec.MakeMeasureSpec(heightMeasureSpec,MeasureSpecMode.Exactly));
   }
   protected override void UnLoad()
   {
      if (this.Parent != null)
           (this.Parent as VirtualizingCellsControl).RemoveView(this);
   }
}

 

Refer the following screenshot for the final outcome

Screeenshot in Xamarin GridCell

 

You can download the working sample for this KB from the below link.

https://www.syncfusion.com/downloads/support/directtrac/general/ze/OtherControlInGrid-1315330641

Conclusion

I hope you enjoyed learning how to insert other controls inside a GridCell in Xamarin.Android DataGrid.

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 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