Wrap RadDataGrid with RadScrollView and data disappeared

1 Answer 69 Views
DataGrid
Daniel
Top achievements
Rank 1
Silver
Bronze
Daniel asked on 31 Mar 2022, 07:27 AM

Hi,

I wrap RadDataGrid with RadScrollView and data disappeared. why?

Thanks,

<telerikMauiControls:RadScrollView HeightRequest="200">
                <telerikDataGrid:RadDataGrid  x:Name="schedulersDataGrid" Margin="10" ItemsSource="{Binding SchedulersSource, Mode=TwoWay}"
                AutoGenerateColumns="False"  SelectionMode="Single" SelectionUnit="Row" SelectedItem="{Binding SelectedSchedulerItem, Mode=TwoWay}">
                    <telerikDataGrid:RadDataGrid.AlternateRowBackgroundStyle>
                        <telerikDataGrid:DataGridBorderStyle BackgroundColor="LightBlue"
                                     BorderThickness="1"
                                     BorderColor="BlanchedAlmond"/>
                    </telerikDataGrid:RadDataGrid.AlternateRowBackgroundStyle>
                    <telerikDataGrid:RadDataGrid.Columns>
                        <telerikDataGrid:DataGridTextColumn PropertyName="Name" HeaderText="Name" HeaderStyle="{StaticResource DataGridTextColumnHeaderStyle}"/>
                        <telerikDataGrid:DataGridTextColumn PropertyName="FreqType" HeaderText="Type" HeaderStyle="{StaticResource DataGridTextColumnHeaderStyle}"/>
                        <telerikDataGrid:DataGridTextColumn PropertyName="ActiveStartDate" HeaderText="Start Date" HeaderStyle="{StaticResource DataGridTextColumnHeaderStyle}"/>
                        <telerikDataGrid:DataGridTextColumn PropertyName="ActiveEndDate" HeaderText="End Date" HeaderStyle="{StaticResource DataGridTextColumnHeaderStyle}"/>
                    </telerikDataGrid:RadDataGrid.Columns>
                </telerikDataGrid:RadDataGrid>
             </telerikMauiControls:RadScrollView >


1 Answer, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 01 Apr 2022, 05:17 AM

Hello Daniel,

RadDataGrid provides UI virtualization for optimization purposes, so it relies on its parent container to provide space to fall into. In additon, the DataGrid has its own scrolling mechanism, which is enabled when there isn't enough space. RadScrollView, on the other hand, as well as StackLayout and other containers, relies on its children to measure themselves. 

That's why it is not a recommended practice to place virtualized controls (DataGrid, ListView) into StackLayouts, ScrollViews and Grid with "Auto" size as it could lead to various unexpected results. You can either use a Grid with "*" size or explicitly set HeightRequest property to the DataGrid.

We have a very useful article on the matter in our Xamarin documentation - you can take a look at: Problem: Controls Are Not Appearing  - we're going to include the information in our .NET MAUI documentation as well.

I hope I was of help.

Regards,
Yana
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Daniel
Top achievements
Rank 1
Silver
Bronze
commented on 03 Apr 2022, 09:19 AM

I used first approach- setting height to grid.
Tags
DataGrid
Asked by
Daniel
Top achievements
Rank 1
Silver
Bronze
Answers by
Yana
Telerik team
Share this question
or