WPF datagrid takes a long time to load

Scenario

myDataGrid is in a simple WPF Grid control where a RowDefinition has a Height=”*”

<Grid >
   <Grid.RowDefinitions>
   <RowDefinition Height=”*” />
</Grid.RowDefinitions>

And if myDataTable has a large row count then the following may ‘hang’ or take a long time to load on following code:

myDataGrid.ItemsSource = myDataTable.DefaultView

The issue is that if the DataGrid is in a control that has unlimited height then it will render the whole DataGrid.

 

Solution

Options to resolve this include:

  1. Changing the RowDefinition Height
  2. Add MaxHeight to the DataGrid, so <DataGrid x:Name=”myDataGrid” MaxHeight=”1000″ />

Performance is then fine.

With thanks to: http://stackoverflow.com/questions/3336921/unreasonable-wpf-datagrid-loading-time

End.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: