Index Out of range with DataGrid

I am building an application and am running into an issue I can't seem to figure out. I have the latest (as of 1/17/2018) Syncfusion bits and am running the latest Visual Studio 2017 (15.5.4). I have built a simple repro of my app and that works so it must be something I am doing in my app but I can't seem to figure it out. Hoping someone here may have run into this or can give me some pointers.
I am using the sfDataGrid control and I am trying to bind a List to the ItemsSource in my code behind. If I leave AutoGenerateColumns = 'True' all works as it should but I am getting all the columns, I only want a handful. When I set AutoGenerateColumns = 'False' and set the SfDataGrid.Columns up in the XAML with only the columns I want to show I crash when setting the ItemsSource to my collection. I receive the following error:
Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
Here is my XAML:

               <sfdg:SfDataGrid x:Name="RankingDataGrid"            
                                 ColumnSizer="Auto"
                                 AutoGenerateColumnsMode="None"
                                 AutoGenerateColumns="False" 
                                 BackgroundColor="#404040">

                    <sfdg:SfDataGrid.Columns x:TypeArguments="syncfusion:Columns">
                        <sfdg:GridTextColumn HeaderText="Rank" 
                                             MappingName="National.Current.Rank" />
                        <sfdg:GridTextColumn HeaderText="Team"
                                             MappingName="TeamName" />
                        <sfdg:GridTextColumn HeaderText="Wins"
                                             MappingName="National.Current.Wins" />
                        <sfdg:GridTextColumn HeaderText="Losses"
                                             MappingName="National.Current.Losses" />
                        <sfdg:GridTextColumn HeaderText="Matches"
                                             MappingName="National.Current.Matches" />
                        <sfdg:GridTextColumn HeaderText="Win %"
                                             MappingName="National.Current.WinsRatio" />

                    </sfdg:SfDataGrid.Columns>

                </sfdg:SfDataGrid>


In the codebehind I simply do this:

RankingDataGrid.ItemsSource = ranking.Teams;


Anyone have any pointers or ideas? Did I miss a step? Forget to set a property? Like I said, I tried to create a simple repro to show it was a bug, but my repro actually works so I'm at a loss.

3 Replies

SS Sivaraman Sivagurunathan Syncfusion Team January 18, 2018 06:07 PM UTC

Hi John, 
 
Thanks for using syncfusion support. 
 
We have checked your query and prepared sample to reproduce the reported issue. But we could not able to reproduce the issue on our side. We have attached the sample runnable video for your reference you can download the same from the below link. It would be helpful to us if you could provide any of the following to resolve the issue.  
 
  • What are the settings that are given to SfDataGrid and its parent?
  • Could you please modify the given sample to reproduce the issue in our side so that we can help you faster?
 
 
Regards, 
Sivaraman 



JO John January 19, 2018 03:19 PM UTC

I have modified my repro to use one of data sets I am actually using that causes the problem.  Attached you will find the repro you can run.  I have only been running the UWP version, not sure if problems are also on Android and iOS but I will try them today to see and reply with an update.  Basically run the app and click the first button, you will get a page with the data showing fine.  Then go back and click the second button.  This page does the same thing, the only difference is it has AutoGenerateColumns set to false and has defined the columns I want to show.  It will crash.  It is doing the same work to get the data and bind it to the grids ItemSource.

Attachment: sfGridViewRepro_1dd9868d.zip


SS Sivaraman Sivagurunathan Syncfusion Team January 22, 2018 10:48 AM UTC

Hi John,   
   
Sorry for the inconvenience caused.   
   
We have checked the reported “Index was out of range. Must be non-negative and less than the size of the collection” issue from our side. This is a known issue from our side and we have fixed it from our side. The fix will be included in our 2018 Vol 1 main release which is scheduled to rolled out by the mid of February, 2017.    
   
Regards,   
Sivaraman     


Loader.
Up arrow icon