We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

sfdatagrid wont display in relative layout xamarin forms

the datagrid does not display in the relative layout see code below

when i change the line Content =  relativeLayout; to Content = POGrid the grid displays as it should.
can you tell me where i am going wrong i have doublechecked the references

this is in both android and uwp. i am not using ios

thanks
andrew

i am using visual studio 2017 to code



using System;
using System.Collections.Generic;
using System.Text;
using Xamarin.Forms;

using Syncfusion.SfDataGrid.XForms;


    class RelativeLayoutExample : ContentPage
    {
            SfDataGrid POGrid;
        public RelativeLayoutExample()
        {
            RelativeLayout relativeLayout = new RelativeLayout();
            Label upperLeft = new Label { Text = "Supplier", FontSize = 20 };
            relativeLayout.Children.Add(upperLeft, Constraint.Constant(10),Constraint.Constant(0));
            Entry SName = new Entry { Placeholder = "Name",FontSize=15 };
            relativeLayout.Children.Add(SName, Constraint.Constant(5), Constraint.Constant(30), Constraint.Constant(300),null);
            Entry SAdd1 = new Entry { Placeholder = "Add1", FontSize = 15 };
            relativeLayout.Children.Add(SAdd1, Constraint.Constant(5), Constraint.Constant(65), Constraint.Constant(300), null);
            Entry SAdd2 = new Entry { Placeholder = "Add2", FontSize = 15 };
            relativeLayout.Children.Add(SAdd2, Constraint.Constant(5), Constraint.Constant(100), Constraint.Constant(300), null);
            Entry SAdd3 = new Entry { Placeholder = "Add3", FontSize = 15 };
            relativeLayout.Children.Add(SAdd3, Constraint.Constant(5), Constraint.Constant(135), Constraint.Constant(300), null);
            Entry SAdd4 = new Entry { Placeholder = "Add4", FontSize = 15 };
            relativeLayout.Children.Add(SAdd4, Constraint.Constant(5), Constraint.Constant(170), Constraint.Constant(300), null);
            Label LSContact = new Label { Text = "Contact", FontSize = 20 };
            relativeLayout.Children.Add(LSContact, Constraint.Constant(5), Constraint.Constant(205));
            Entry SContact = new Entry { Placeholder = "Contact", FontSize = 15 };
            relativeLayout.Children.Add(SContact, Constraint.Constant(90), Constraint.Constant(205), Constraint.Constant(215), null);
            Label LSTel = new Label { Text = "Telephone", FontSize = 20 };
            relativeLayout.Children.Add(LSTel, Constraint.Constant(5), Constraint.Constant(240));
            Entry STelephone = new Entry { Placeholder = "Telephone", FontSize = 15 };
            relativeLayout.Children.Add(STelephone, Constraint.Constant(90), Constraint.Constant(240), Constraint.Constant(215), null);
            Label LSFax = new Label { Text = "Fax", FontSize = 20 };
            relativeLayout.Children.Add(LSFax, Constraint.Constant(5), Constraint.Constant(275));
            Entry SFax = new Entry { Placeholder = "Fax", FontSize = 15 };
            relativeLayout.Children.Add(SFax, Constraint.Constant(90), Constraint.Constant(275), Constraint.Constant(215), null);
            Label LSEmail = new Label { Text = "Email", FontSize = 20 };
            relativeLayout.Children.Add(LSEmail, Constraint.Constant(5), Constraint.Constant(310));
            Entry SEmail = new Entry { Placeholder = "Email", FontSize = 15 };
            relativeLayout.Children.Add(SEmail, Constraint.Constant(90), Constraint.Constant(310), Constraint.Constant(215), null);

        
         
            relativeLayout.VerticalOptions= LayoutOptions.FillAndExpand;
            relativeLayout.HorizontalOptions= LayoutOptions.FillAndExpand;
            OrderInfoRepository viewModel = new OrderInfoRepository();
            POGrid = new SfDataGrid();
            POGrid.ColumnSizer = ColumnSizer.Star;
            POGrid.ItemsSource = viewModel.OrderInfoCollection;
            POGrid.VerticalOptions= LayoutOptions.FillAndExpand;
            POGrid.HorizontalOptions= LayoutOptions.FillAndExpand;
       
            relativeLayout.Children.Add(POGrid, Constraint.Constant(305), Constraint.Constant(0));

            //  add more views here                
            Content =  relativeLayout;
        }
    }



3 Replies

AN Ashok N Syncfusion Team June 28, 2017 10:36 AM UTC

Hi Andrew, 
 
Thanks for contacting Syncfusion support. 
 
We have checked your code snippet. In your code you have VerticalOptions and HorizontalOptions is LayoutOptions.FillAndExpand, also you have added our SfDataGrid to RelativeLayout without Width and Height Constraint. Our SfDataGrid is derived from Grid and Grid didn’t have default height and width so SfDataGrid does not display in view. You can achieve your requirement by setting Width and Height Constraint to SfDataGrid. Please refer the below code example  
 
relativeLayout.Children.Add(POGrid, Constraint.Constant(0), Constraint.Constant(315), Constraint.Constant(300), Constraint.Constant(300)); 
 
 
Regards, 
Ashok


AS Andrew Simpson June 29, 2017 08:20 AM UTC

Thank you that worked.. 



AN Ashok N Syncfusion Team June 30, 2017 05:33 AM UTC

Hi Andrew,  
 
Thanks for your update. Please let us know if you require further assistance on this. 
 
Regards, 
Ashok 


Loader.
Live Chat Icon For mobile
Up arrow icon