Click here to Skip to main content
15,897,891 members

Slow datagrid with ~400 rows

m.bleimuth asked:

Open original thread
HI,

i have a very slow ItemsControl with up to 5 DataGrids in it. (displays next to each other) Everytime when i update this Control my whole UI lags extremly (~10sec). Each Datagrid has ~50-400 items with predifined columns (not autogenerated). The itemsources of the grids get updated at the same time.

Here is my XAML:

XML
<pre>        <ScrollViewer Grid.Row="1">
            <ItemsControl ItemsSource="{Binding}">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <UniformGrid Columns="{Binding Count}"/>
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <DataGrid ItemsSource="{Binding Content}" RowHeight="20" AutoGenerateColumns="False" VirtualizingPanel.IsVirtualizing="True" VirtualizingPanel.VirtualizationMode="Recycling">
                            <DataGrid.Columns>
                                <DataGridTextColumn Header="name" Binding="{Binding Name}" Width="100"  />
                                <DataGridTextColumn Header="value" Binding="{Binding Value}" Width="50" />
                            </DataGrid.Columns>
                        </DataGrid>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
        </ScrollViewer>


And here the Code Behind:

C#
public partial class MainWindow : Window
   {

       public List<Folder> Folders { get; set; }

       public MainWindow()
       {
           InitializeComponent();

           Folders = new List<Folder>();
           Folders.Add(new Folder());
           Folders.Add(new Folder());

           this.DataContext = Folders;
       }

       private void Button_Click(object sender, RoutedEventArgs e)
       {
           Folders.ForEach(f => f.UpdateData());
       }
   }


   public class Folder
   {
       private  Random _rand = new Random();
       public ObservableCollection<Content> Content { get; set; }

       public Folder()
       {
           Content = new ObservableCollection<Content>();
       }

       public void UpdateData()
       {
           Content.Clear();
           for(int i = 1; i <= 300; i++)
               Content.Add(new Content($"C{i}", _rand.Next(1,400)));
       }
   }

   public class Content
   {
       public string Name  { get; set; }
       public int Value    { get; set; }

       public Content(string name, int value)
       {
           Name    = name;
           Value   = value;
       }
   }



Pls find also attached a full working example here.

Any ideas how i can speed up the datagrids without blocking the whole UI?

KR Manu

What I have tried:

I have tried to replace the datagrids with listboxes but the UI is still blocking.
Well it's not blocking that long but i need a solution without blocking at all.
Tags: C# 6.0, WPF, DataGrid

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900