using SFdatagrid on existing layout

Hello there, I am trying out SFdatagrid, and I see samples in Xamarin android show the control being added to a simple layout that gets added and bound via SetContentView.  I am adding to a pre-build layout I first gather with SetContentView.  I then use Findlayout to locate a linearlayout I have in place.

For some reason, the grid is not resizing to full width, though the linear layout width = match_parent.  Any thoughts?  Is this the correct way to do this?

            // setup grid
            var layUOMContainer = FindViewById<LinearLayout>(Resource.Id.layUOMContainer);
            _itemDataGrid = new SfDataGrid(this)
            {
                AllowSorting = true,
                AutoGenerateColumns = false,
                ColumnSizer = ColumnSizer.Auto,
               
            };

            _itemDataGrid.Columns.Add(new GridTextColumn() { HeaderText = "UOM", MappingName = "UOMID", HeaderCellTextSize=24, CellTextSize = 20});
            _itemDataGrid.Columns.Add(new GridTextColumn() { HeaderText = "List Price", MappingName = "UnitPrice", Format = "{0:c}",
                HeaderCellTextSize = 24, CellTextSize = 20} );
            layUOMContainer.AddView(_itemDataGrid);


</RelativeLayout>
<!-- Begin Display form layout -->
<LinearLayout
android:id="@+id/layItemView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="false"
android:layout_alignParentTop="false"

android:layout_below="@id/layHeader"
android:orientation="vertical"
android:visibility="visible">

<LinearLayout
android:id="@+id/layItem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="1dp"
android:visibility="visible">

<TextView
android:id="@+id/tvItemDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lines="1"
android:maxLines="3"
android:minLines="1"
android:padding="1dp"
android:textColor="@android:color/black"
android:textSize="24sp"
android:textStyle="bold"
tools:text="Annual" />

<TextView
android:id="@+id/tvItemID"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="2dp"
android:text="ITEMID"
android:textColor="@android:color/black"
android:textSize="24sp"
android:textStyle="bold" />

<LinearLayout
android:id="@+id/layUOMContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="300dp"
android:orientation="vertical"
android:padding="4dp"
android:visibility="visible"></LinearLayout>
</LinearLayout>
</LinearLayout>


1 Reply

JA Jayaraman Ayyanar Syncfusion Team March 27, 2018 11:31 AM UTC

Hi David,     
      
Thanks for contacting Syncfusion support. 
 
We have checked your query for the “using SFdatagrid on existing layout” where you have reported that the DataGrid is not resizing to the full width even though you gave the width = matchparent for the linearlayout. In the given code of DataGrid contains only two columns and the column sizer is set as the Auto so, the column will layout based on the size of the text in the column since the datagrid is layout to the full width of the linear layout that you could see by setting the background color for the record background color by extends the DataGridStyle class. The DataGrid is layout to full width of the Linear Layout which is working fine in our side. If you want to display the column to the full width of the view, set the columnSizer property of DataGrid as Star. 
 
We have tested a sample with the given code and you can download the same from the below link. 
 
Regards,     
Jayaraman. 
 


Loader.
Up arrow icon