How to use the DataGrid?
Posted: Thu Mar 07, 2019 4:47 pm
Hello,
I am using the DataGrid control and having a slowdowns when setting the ItemSource with many records.
Please see my sample code below.
Then my C# code.
But as what I observed, the rendering of the DataGrid (loading, going to previous or next page of the DataGrid) is slow and will hang the UI.
Am I using the correct method?
Will wait for your feedback.
Thanks.
Fernan
I am using the DataGrid control and having a slowdowns when setting the ItemSource with many records.
Please see my sample code below.
Code: Select all
<DataGrid x:Name="DataGrid1" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="Name" Binding="{Binding PersonName}"/>
<DataGridTextColumn Header="Age" Binding="{Binding PersonAge}"/>
<DataGridTextColumn Header="Address" Binding="{Binding PersonAddress}"/>
<DataGridTextColumn Header="Contact Number" Binding="{Binding PersonContactNumber}"/>
</DataGrid.Columns>
</DataGrid>
Then my C# code.
Code: Select all
public class Person
{
public string PersonName { get; set; }
public int PersonAge{ get; set; }
public string PersonAddress{ get; set; }
public string PersonContactNumber{ get; set; }
}
private void FillDataGrid()
{
List<Person> Listing = new List<Person>();
//This loop adds let say 1000 items to the list
for(int index = 0; index < 1000; index++)
{
Person current = new Person();
current = GenerateDummyRecord();
Listing.Items.Add(current);
}
//Sets the Listing as the item source of DataGrid
DataGrid1.ItemsSource = Listing;
}
But as what I observed, the rendering of the DataGrid (loading, going to previous or next page of the DataGrid) is slow and will hang the UI.
Am I using the correct method?
Will wait for your feedback.
Thanks.
Fernan