Can you disable horizontal scroll or is there a property like SizeToCells like in WPF?

Hi,

Is it possible to set a property on the datagrid to disable horizontal scrolling? Or is there a property like  SizeToCells  in WPF. I have a datagrid that has 4 columns, and I want those colums to be the size of the content, but if I use ColumnSizer = Auto, then the datagrid expands and it goes out of the mobile screen and you can scroll. 


What I want is the ability to show the complete datagrid with no horizontal scrolling, and that the colums adjust to take just the amount of space they need.


As you can see from the picture, the last two columns could be just small enough so that everything fits on the screen, because they don't have much content in them..


Kind regards,

Matej


1 Reply 1 reply marked as answer

SV Suja Venkatesan Syncfusion Team May 4, 2022 01:48 PM UTC

Hi Matej,


We would like to inform you that ,currently we don’t have ColumnSizer value as SizeToCell and also no property for disabling horizontal scrolling in Xamarin.Android. If we set Columnsizer with value as Star, all the GridColumns are adjusted an equal column width to fit within the view. Setting ColumnSizer to Star will disable the horizontal scrolling in the SfDataGrid.


Please refer our user Guidelines documentation regarding ColumnSizer as Star.

UG link: https://help.syncfusion.com/xamarin-android/sfdatagrid/column-sizer#columnsizerstar


You can achieve your requirement ”Show the complete datagrid with no horizontal scrolling” by defining the width to the SfDataGrid as like below code snippet.


Code Snippet:

protected override void OnCreate (Bundle bundle)

{

dataGrid = new SfDataGrid(this);

viewModel = new OrderInfoRepository();

ScreenWidth = (int)Resources.DisplayMetrics.WidthPixels;

dataGrid.ColumnSizer = ColumnSizer.Auto;

dataGrid.GridLoaded += DataGrid_GridLoaded;

}

 

private void DataGrid_GridLoaded(object sender, GridLoadedEventArgs e)

{

  var dataGrid = (sender as SfDataGrid);

  double ld_Width = 0;

  foreach (var item in dataGrid.Columns)

  {

     if (!(Double.IsNaN(item.ActualWidth)))

     {

        ld_Width += item.ActualWidth;

     }

  }

 

 if (ld_Width < ScreenWidth)

 {

    dataGrid.LayoutParameters.Width=(int) ld_Width;

 }

 

 else if (ld_Width >= ScreenWidth)

 {

     //subract 10 for padding of SfDataGrid

    dataGrid.LayoutParameters.Width =ScreenWidth-10;

  }

}


We have attached a simple sample based on your requirement for your reference. Please have look at this sample and let us know if you have any concern.


Regards,

Suja


Attachment: F174797_2741d3c9.zip

Marked as answer
Loader.
Up arrow icon