int nIndex = 0; private async void BtnMeasureClick(object sender, EventArgs e) { PhotometricMeasureData test = new PhotometricMeasureData(); ++nIndex; test.No = nIndex.ToString(); test.Cell = string.Format("C[{0}]", nIndex); test.DateTime = DateTime.Now;
for (int i = 0; i < this.m_Model.WaveLength.Count; i++) { test.ABS.Add(new Random().Next(-10, 10)); test.Trans.Add(new Random().Next(-10, 10)); }
this.m_Model.MeasureData.Add(test);
int n = this.m_Model.MeasureData.Count; this.xDataGrid.ScrollToLastRowByIndex(n); }
public ObservableCollection<PhotometricMeasureData> MeasureData { set; get; } = new ObservableCollection<PhotometricMeasureData>();
public class PhotometricMeasureData { public string No { get; set; } public string Cell { get; set; } public DateTime DateTime { get; set; } public List<float> ABS { get; set; } = new List<float>();
public List<float> Trans { get; set; } = new List<float>(); }
Click the button to create and insert virtual data. But it doesn't move to the last line.
Is there any other reason? One strange thing is that you shouldn't put count in the index, but if you set it to int n = 10 it will work.
is this a bug?
Hello,
I have modified the sample project that I sent you with the relevant code that you have provided and on my end, the grid still scrolls if I pass the Count of my data source minus 1.
For consistency, I am attaching the modified version of the sample project so you can try it on your end. Please run it on your end, as it may help to further narrow down what the issue is here.
If the sample works, this means there is still something specific about the code in your application that is preventing the scroll.
If the sample does not work, this means there is a difference in the environment that we are testing in or perhaps the assemblies that we are targeting. My tests were made against version 20.1.35 of the Infragistics for Xamarin toolset. I tested on a Google Pixel 3 device against Android version 12.
Please let me know if you have any other questions or concerns on this matter.
8741.XFGridScrollTest.zip
<ContentPage:ComponentCommon x:Class="POP.Component.Photometric.Photometric_Main" xmlns="">xamarin.com/.../forms" xmlns:x="">schemas.microsoft.com/.../xaml" xmlns:ContentPage="clr-namespace:POP.Component" xmlns:Ctrl="clr-namespace:POP.Controls" xmlns:Local="clr-namespace:KLAB.Localizations.Words;assembly=Localizations" xmlns:charts="clr-namespace:Infragistics.XamarinForms.Controls.Charts;assembly=Infragistics.XF.Charts" xmlns:igGrid="clr-namespace:Infragistics.XamarinForms.Controls.Grids;assembly=Infragistics.XF.DataGrid" BackgroundColor="{StaticResource ColorBack001}">
<Grid> <Grid.RowDefinitions> <RowDefinition Height="58" /> <RowDefinition Height="1*" /> <RowDefinition Height="60" /> </Grid.RowDefinitions>
<Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions>
<!-- 상시 측정 화면 표시 --> <ContentView x:Name="xRealTimeMeasureComp" Grid.Row="0" Grid.Column="0" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" />
<Grid x:Name="xGrdMainContents" Grid.Row="1" Grid.Column="0" Margin="5,0,5,0" ColumnSpacing="0">
<Grid.ColumnDefinitions> <ColumnDefinition x:Name="xGrdMainChart" Width="*" /> </Grid.ColumnDefinitions>
<Frame Grid.Column="0" Padding="1" BackgroundColor="{StaticResource ColorBorder000}" HasShadow="False"> <Frame Padding="0" BackgroundColor="{StaticResource ColorBack002}" HasShadow="false">
<igGrid:XamDataGrid x:Name="xDataGrid" Margin="5,5,0,0" BackgroundColor="{StaticResource ColorBack002}" />
</Frame> </Frame> </Grid>
<!--#region Bottom Buttons (Blank, Measure)--> <StackLayout x:Name="xSlBotTools" Grid.Row="2" Grid.Column="0" Margin="5,-2,0,5" HorizontalOptions="Start" Orientation="Horizontal" Spacing="10">
<Ctrl:CtrlOptionButton x:Name="m_btnOption" Event_OptionButton_Click="BtnOptionMenuClick" WidthRequest="60" /> <Ctrl:CtrlButton x:Name="xbtnBlank" Clicked="BtnBlankClick" Text="Blank" WidthRequest="190" /> <Ctrl:CtrlButton x:Name="xbtnMeasure" Clicked="BtnMeasureClick" Text="Measure" WidthRequest="190" /> </StackLayout> <!--#endregion-->
<!--<StackLayout Grid.Row="2" Grid.Column="0" Margin="0,-2,5,5" HorizontalOptions="End" Orientation="Horizontal"> <Ctrl:CtrlButton x:Name="xbtnViewChange" Clicked="BtnViewChangeClick" HorizontalOptions="End" Text="View Change" WidthRequest="190" /> </StackLayout>--> </Grid>
</ContentPage:ComponentCommon>
Please understand that we cannot send sample source code because multiple projects are linked.
Attach Xaml content. please check once more
I have tried using the same recommendation I made to you, and interestingly, it works on my end. To prove this, I am attaching a simple sample project to demonstrate.
This leads me to believe that there is some difference between the sample I wrote and the way that your grid is on your page. By chance, are you placing the grid within a scrollable container or stack layout or something along those lines? I ask, as these containers will measure their content with an infinite height/width, which may “trick” the grid into thinking that all of its rows are already in view because the grid isn’t actually scrolling – the page / container is.
Can you please provide some additional information regarding the container that the grid is placed in or potentially modify the sample I am sending you and send it back such that it reproduces the behavior you are seeing? Alternatively, if you have an isolated sample of your own, I will gladly take a look at that.
XFGridScrollTest.zip
I changed it to MeasureData.Count–1 and tested it, but it's still the same.
I am doing android development using Xamarin forms.
I have been investigating into the behavior you are seeing, and I am curious first to know if this was posted in the correct location. I see it was posted in our “Android” forums specifically, but it sounds like you are asking about the XamDataGrid which could be a Xamarin.Forms or WPF control. Can you please confirm which platform you are using and I will move this forum thread to the correct location if needed?
Looking at the code you have provided, it looks like you are trying to scroll to a row at an index equal to MeasureData.Count. Indexes are 0-based, so I am curious if this works for you if you try to scroll MeasureData.Count – 1?