two SfDataGrids on Android Layout

Hi,
i am struggling to find a way to combine two sfdatagrid in one Layout.
Thanks in Advance,
James Dimitrako

3 Replies

SR Sivakumar R Syncfusion Team July 11, 2018 10:55 AM UTC

Hi James, 
 
You can load two datagrid’s in one layout by specifying width and height. 
 
Can you please let us know the layout you are trying to load and the problem you are facing. This will helps to provide better solution to meet your requirement. 
 
Thanks, 
Sivakumar 



JD James Dimitrako July 11, 2018 11:05 AM UTC

Hi and thanks for your quick answer,

firstly i am working on xamarin.android and not in xamarin.forms.

Here my code:

XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:minWidth="25px"
    android:minHeight="25px">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minWidth="25px"
        android:minHeight="25px">
        <android.support.design.widget.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/barcode" />
        <Button
            android:text="getData"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/getData" />
        <RelativeLayout
            android:minWidth="25px"
            android:minHeight="25px"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/Relative"
            android:layout_marginRight="0.0dp" />
    </LinearLayout>
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minWidth="25px"
        android:minHeight="25px">
        <android.support.design.widget.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/barcodeSent" />
        <Button
            android:text="getData"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/getDataSent" />
        <RelativeLayout
            android:minWidth="25px"
            android:minHeight="25px"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/RelativeSent" />
    </LinearLayout>
</LinearLayout>


and my main activity:

 SfDataGrid dataGrid;
        SfDataGrid dataGridSent;
        ViewBasketModel viewModel;
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.activity_main);




            //init Items
            RelativeLayout layout = FindViewById<RelativeLayout>(Resource.Id.RelativeSent);
            RelativeLayout layoutSent = FindViewById<RelativeLayout>(Resource.Id.RelativeSent);
            TextView barcode = FindViewById<TextView>(Resource.Id.barcode);
            TextView barcodeSent = FindViewById<TextView>(Resource.Id.barcodeSent);
            Button sendData = FindViewById<Button>(Resource.Id.getData);
            Button sendDataSent = FindViewById<Button>(Resource.Id.getDataSent);

            //init Datagrid
            dataGrid = new SfDataGrid(this);
            dataGridSent = new SfDataGrid(this);
            layout.AddView(dataGrid);
            layoutSent.AddView(dataGridSent);

            viewModel = new ViewBasketModel(1454);
           
            dataGrid.ItemsSource = viewModel.DynamicJsonCollection;
            dataGridSent.ItemsSource = viewModel.DynamicJsonCollection;

       ..................................


Regards,
James



SK Shivagurunathan Kamalakannan Syncfusion Team July 12, 2018 09:01 PM UTC

Hi James, 
 
We have analyzed the provided code and prepared a sample based on it.  
 
Refer the below code for refernce. 
 
public sealed class MainActivity : Activity 
{ 
    SfDataGrid dataGrid; 
    SfDataGrid dataGridSent; 
    protected override void OnCreate(Bundle bundle) 
    { 
        base.OnCreate(bundle); 
        SetContentView(Resource.Layout.Main); 
 
        LinearLayout layoutcontent = FindViewById<LinearLayout>(Resource.Id.linearcontent); 
        RelativeLayout Relative = FindViewById<RelativeLayout>(Resource.Id.Relative); 
        RelativeLayout RelativeSent = FindViewById<RelativeLayout>(Resource.Id.RelativeSent); 
        TextView barcode = FindViewById<TextView>(Resource.Id.barcode); 
        TextView barcodeSent = FindViewById<TextView>(Resource.Id.barcodeSent); 
        Button sendData = FindViewById<Button>(Resource.Id.getData); 
        Button sendDataSent = FindViewById<Button>(Resource.Id.getDataSent); 
 
        // Set our view from the "main" layout resource 
 
        dataGrid = new SfDataGrid(this); 
        dataGridSent = new SfDataGrid(this); 
        OrderInfoRepository viewmodel = new OrderInfoRepository(); 
        dataGrid.ItemsSource = viewmodel.OrderInfoCollection; 
 
        dataGrid.AutoGenerateColumns = false; 
 
        GridTextColumn orderIDColumn = new GridTextColumn() { MappingName = "OrderID"}; 
        dataGrid.Columns.Add(orderIDColumn); 
 
        GridTextColumn shipCityColumn = new GridTextColumn() { MappingName = "ShipCity" }; 
        dataGrid.Columns.Add(shipCityColumn); 
 
        GridTextColumn shipCountryColumn = new GridTextColumn() { MappingName = "ShipCountry"}; 
        dataGrid.Columns.Add(shipCountryColumn); 
 
        dataGrid.ColumnSizer = ColumnSizer.Star; 
 
        dataGridSent.ItemsSource = viewmodel.OrderInfoCollection; 
        GridTextColumn orderIDColumnmatch = new GridTextColumn() { MappingName = "OrderID" }; 
        dataGridSent.Columns.Add(orderIDColumnmatch); 
 
        GridTextColumn customerIDColumn = new GridTextColumn() { MappingName = "CustomerID" }; 
        dataGridSent.Columns.Add(customerIDColumn); 
 
        GridTextColumn CustomerColumn = new GridTextColumn() { MappingName = "Customer" }; 
        dataGridSent.Columns.Add(CustomerColumn); 
        dataGridSent.AutoGenerateColumns = false; 
 
        dataGridSent.ColumnSizer = ColumnSizer.Star; 
 
 
        Relative.AddView(dataGrid, 1050, 500); 
        RelativeSent.AddView(dataGridSent, 1050, 500); 
    } 
     
 
} 
 
 
 
You can download the sample from the below link. 
 
The resultant image of the sample is attached below. 
 
 
Regards, 
Shivagurunathan 
 


Loader.
Up arrow icon