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

Is there any way to align SfDataGrid as a centered in Grid or ContentView

Maybe this is a very simple problem but I could not succeed this. My SfDataGrid could not be located centrally at horizontal and vertical in Grid or ContentView.

For Example: In a Grid;

            <ContentView Grid.Row="1" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
                <syncfusion:SfDataGrid HorizontalOptions="Center" VerticalOptions="Center" AllowEditing="False" AllowResizingColumn="False" ColumnSizer="Auto"></syncfusion:SfDataGrid>
            </ContentView>

When I enter these codes, the data grid is not positioned horizontally and vertically. Every time, located according to the left side.

3 Replies

BS Balasubramani Sundaram Syncfusion Team November 29, 2019 06:45 PM UTC

Hi Xamarin Hunter,  
 
Thank you for contacting Syncfusion support.   
 
Based on your provided code snippet we analyzed, if we set the column sizer to auto and LayoutOption to SfDataGrid, it will load at the center with minimum width and height measurements, you must set the MinimumWidthRequest to "0" to get the proper layout at the center. 
 
Please refer the below sample and code snippet,  
 
Code Snippet [C#] 
 
<ContentPage.Content> 
    <ContentView HorizontalOptions="FillAndExpand"  
                     VerticalOptions="FillAndExpand"> 
        <syncfusion:SfDataGrid  
                               ColumnSizer="Auto" 
                               HorizontalOptions="Center" 
                               VerticalOptions="Center" 
                               MinimumWidthRequest="0" 
                               AutoGenerateColumns="False" 
                               ItemsSource="{Binding OrdersInfo}"> 
            <syncfusion:SfDataGrid.Columns> 
                ....... 
                ....... 
                ....... 
            </syncfusion:SfDataGrid.Columns> 
        </syncfusion:SfDataGrid> 
    </ContentView> 
</ContentPage.Content> 
 
 
 
  
 
 
We hope this helps. Please let us know, if you need any further assistance. 
 
Regards,
Balasubramani Sundaram.
 
 



XH Xamarin Hunter replied to Balasubramani Sundaram November 29, 2019 08:00 PM UTC

Hi Xamarin Hunter,  
 
Thank you for contacting Syncfusion support.   
 
Based on your provided code snippet we analyzed, if we set the column sizer to auto and LayoutOption to SfDataGrid, it will load at the center with minimum width and height measurements, you must set the MinimumWidthRequest to "0" to get the proper layout at the center. 
 
Please refer the below sample and code snippet,  
 
Code Snippet [C#] 
 
<ContentPage.Content> 
    <ContentView HorizontalOptions="FillAndExpand"  
                     VerticalOptions="FillAndExpand"> 
        <syncfusion:SfDataGrid  
                               ColumnSizer="Auto" 
                               HorizontalOptions="Center" 
                               VerticalOptions="Center" 
                               MinimumWidthRequest="0" 
                               AutoGenerateColumns="False" 
                               ItemsSource="{Binding OrdersInfo}"> 
            <syncfusion:SfDataGrid.Columns> 
                ....... 
                ....... 
                ....... 
            </syncfusion:SfDataGrid.Columns> 
        </syncfusion:SfDataGrid> 
    </ContentView> 
</ContentPage.Content> 
 
 
 
  
 
 
We hope this helps. Please let us know, if you need any further assistance. 
 
Regards,
Balasubramani Sundaram.
 
 


Thank you for your answer. I've tried the code block instance you mentioned; When I compile the application, a problem occurs: the datagrid is located in the center but then, it is placed to the left. I don't understand this problem. Here is my code:

            <ContentView Grid.Row="6" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
                <syncfusion:SfDataGrid MinimumWidthRequest="0" HorizontalOptions="Center" VerticalOptions="Center" BackgroundColor="Transparent" AllowEditing="False" AllowResizingColumn="False" ColumnSizer="Auto" AutoGeneratingColumn="MyAlter_AutoGeneratingColumn"></syncfusion:SfDataGrid>
            </ContentView>




BS Balasubramani Sundaram Syncfusion Team December 2, 2019 02:05 PM UTC

Hi Utemar, 
 
Thanks for the update.     
 
We have tried your code snippet in our earlier provided sample, in that instead of creating a column manually we have AutoGenerated them and in AutoGeneratingColumn event we have done some customization then also it is working fine as we expected. 
 
Please refer the sample and code snippet,  
 
Code Snippet [C#] 
 
[MainPage.Xaml] 
 
<ContentPage.Content> 
    <ContentView HorizontalOptions="FillAndExpand"  
                 VerticalOptions="FillAndExpand"> 
        <syncfusion:SfDataGrid  
                           x:Name="myGrid"   
                           ColumnSizer="Auto" 
                           HorizontalOptions="Center" 
                           VerticalOptions="Center" 
                           MinimumWidthRequest="0" 
                           AllowResizingColumn="False" 
                           AutoGenerateColumns="True" 
                           AutoGeneratingColumn="myGrid_AutoGeneratingColumn" 
                           ItemsSource="{Binding OrdersInfo}"> 
        </syncfusion:SfDataGrid> 
    </ContentView> 
</ContentPage.Content> 
 
 
 
 
 
Android  
 
 
 
UWP 
 
 
 
Note: Issue has been checked with Xamarin. Forms version 3.6 and Syncfusion NuGet version 17.3.0.28 
    
Please check the sample and let us know if you still facing the same issue? If not, please modify the sample based on your scenario and revert us with the more details, so that it will be helpful for us to check on it and provide you the solution at the earliest.    
 
Regards,
Balasubramani Sundaram.
 
 


Loader.
Live Chat Icon For mobile
Up arrow icon