WPF DATAGRID Databinding Slow

Sep 21, 2009 at 8:46 AM

Hi a question
i made a test with 1500 records read from db (with 20 properties). One time with winforms and one time with wpf toolkit.
The winforms applications reads the 1500 records immediatly. The wpf app takes a lot of time.

The only code that i made in the frontends is the following:

WPF:
private void button1_Click(object sender, RoutedEventArgs e)
        {
            LoadData();
        }

        private void LoadData()
        {
            long count;
            dataGrid1.ItemsSource = OrganisationBL.ReadAllOrganisationsBySearchTerm("%" + textBoxSearch.Text + "%", null, null, null, out count);
        }

winforms:
private void LoadData()
        {
            long count;
            dataGridView1.DataSource = OrganisationBL.ReadAllOrganisationsBySearchTerm("%" + textBox1.Text + "%", null, null, null, out count);           
        }

        private void button1_Click(object sender, EventArgs e)
        {
            LoadData();
        }

WPF XAML:
<Window x:Class="Siag.TEST.WPF.WPF.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="768" Width="1024" xmlns:my="http://schemas.microsoft.com/wpf/2008/toolkit">
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal" Margin="5">       
            <StackPanel Margin="2"><TextBox Width="400" x:Name="textBoxSearch"></TextBox></StackPanel>
            <StackPanel Margin="2">
            <Button x:Name="button1" Width="100" Content="Search" IsDefault="True" Click="button1_Click"></Button></StackPanel>        
        </StackPanel>
        <StackPanel>           
                <my:DataGrid Name="dataGrid1" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"
                     AutoGenerateColumns="true"
                     SelectionMode="Extended"
                     ItemsSource="{Binding}">
            <!--<my:DataGrid.Columns>
                <my:DataGridTextColumn Header="NameDe" Width="Auto" Binding="{Binding Path=NameDe}"/>
            </my:DataGrid.Columns>-->
                   
        </my:DataGrid>               
            </StackPanel>
    </StackPanel>
   
</Window>

Did i made something wrong? Or this is the standard behavior?
Thanks
Christoph

 

Sep 21, 2009 at 9:24 AM

I find datagrid is slow too.  whether load the data or scroll it. wpf is too much slower than vb or vc.


Sep 21, 2009 at 2:56 PM

Hi All,

I also found that the CPU usage is very high when scrolling the DataGrid, anyone have the solution of it?

 

Regards,

Tony