Xamarin.Forms.DataGrid icon indicating copy to clipboard operation
Xamarin.Forms.DataGrid copied to clipboard

Horizontal Scroll Bar in DataGrid

Open JatinRawat03 opened this issue 6 years ago • 12 comments

How can we introduce Horizontal Scroll Bar in the DataGrid ? I have tried using ScrollView and Wrapped the DataGrid inside it but Its not Working.

JatinRawat03 avatar May 30 '18 11:05 JatinRawat03

<RelativeLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">

    <StackLayout x:Name="GridViewLayoutStack" RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width,Factor=1.0}" RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height,Factor=1.0}" VerticalOptions="FillAndExpand" Spacing="0" Padding="0,0,0,0">
    <StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
            <ScrollView Orientation="Both" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
            <dg:DataGrid x:Name="DataGrid002" ItemsSource="{Binding ListeviewItemSource, Mode=TwoWay}" ColumnSpacing="0" Padding="0,0,0,0" HeaderBordersVisible="true" HeaderBackground="Silver" SelectionEnabled="true" BorderColor="Black" Margin="1" BorderThickness="1">
                

******* This one is working fine in my APP. Try it and let me know

bharatkolla11 avatar Jun 03 '18 01:06 bharatkolla11

Can you provide your sample here? Because the above code crashes the Application.

JatinRawat03 avatar Jun 04 '18 11:06 JatinRawat03

ok may i know what the error is ??

bharatkolla11 avatar Jun 06 '18 14:06 bharatkolla11

After adding the code Application just crashes down.

JatinRawat03 avatar Jun 13 '18 06:06 JatinRawat03

the above code that bharat posted here works for me, try double checking your code jatin, it may be that there is another reason why your application crashes.

RanielQuirante avatar Jun 16 '18 06:06 RanielQuirante

@JatinRawat03 Xamarin.UWP does not support nested scroll view, so it will not work

akgulebubekir avatar Jun 20 '18 06:06 akgulebubekir

the scroll view would be so nice if only it could display all the rows... on my side it cuts the last 4 remaining rows... I hope this can be more optimize

Edit: I've learned that it doesn't display all the rows since the scroll control in the datagrid is not being used along with scroll view... if only maybe the datagrid can have a horizontal scroll option... that would be really nice, so it would still look good even if it has a lot of columns

RanielQuirante avatar Jun 21 '18 05:06 RanielQuirante

Hi!

There is a workaround to work in UWP. You need to define RowHeight="-1" for DataGrid

luquettacwb avatar Aug 30 '18 12:08 luquettacwb

Hi! Is it possible to enable horizontal, but still keep it so that the column header is fixed in place / always visible? Using the layout @bharatkolla11 provided, the header scrolls out of viewport, too...

marcelgerber avatar Dec 07 '18 21:12 marcelgerber

    <ScrollView Orientation="Both">
	<dg:DataGrid ItemsSource="{Binding Teams}" SelectionEnabled="True" SelectedItem="{Binding SelectedTeam}"
					 RowHeight="70" HeaderHeight="50" BorderColor="#CCCCCC" HeaderBackground="#E0E6F8"
					 PullToRefreshCommand="{Binding RefreshCommand}" IsRefreshing="{Binding IsRefreshing}"
                    WidthRequest="600" 
					 ActiveRowColor="#8899AA">

daesang avatar May 27 '19 05:05 daesang

I am just learning how to get around in Visual Studios Xamarin Forms on a Mac. I have a lot of learning and have been stumbling along with all the help on the web. I have been working to read a CSV file of 1000 records with 37 columns and view the records in a table format. I have successfully been able to read the file with the file picker addin and display the contents with the free version of the Xamarin.forms.datagrid. After a lot of struggle I am able to display the results in a nice format and the records scroll very nicely. However, I can't get it to scroll the columns and have tried the suggested addition of the "scrollview" suggested above but apparently, it overwhelms the simulator as it never returns the grid whereas without the scroll view results are returned quickly.

So I was wondering if there are plans for any future enhancements to add a column scroll feature. Attached is the example I have been able to create from my datable of 1000 records but only the columns that will fit on the screen are visible and they do not scroll as does the records. I see that some of the commercial versions of Datagrid have this feature but I can't afford these for my purposes. The "free" version of the DevExpress version appears to be no longer supported. This free version Xamarin.forms.datagrid is a nice addition to Xamarin forms and would work great form my purpose if only I could get my grid to scroll the columns

Simulator Screen Shot - IPhone Xs - 2020-05-24 at 19 15 40

cjlcooper1 avatar May 25 '20 00:05 cjlcooper1

    <ScrollView Orientation="Both">
	<dg:DataGrid ItemsSource="{Binding Teams}" SelectionEnabled="True" SelectedItem="{Binding SelectedTeam}"
					 RowHeight="70" HeaderHeight="50" BorderColor="#CCCCCC" HeaderBackground="#E0E6F8"
					 PullToRefreshCommand="{Binding RefreshCommand}" IsRefreshing="{Binding IsRefreshing}"
                    WidthRequest="600" 
					 ActiveRowColor="#8899AA">

This will crash in UWP project with this exception:

  • [x] Exception = {"Error HRESULT E_FAIL has been returned from a call to a COM component."}

divyesh008 avatar Jan 18 '22 10:01 divyesh008