none
Binding DataTable to GridView - Performance getting worse

    Question

  • Hi there,

     

    I have a problem with the performance of binding a DataTable to a Gridview.

     

    The binding itself does function - no problem (binding the datatable to the ListView and the datacolumns to the GridView: )

     

    Code Block

    GridViewColumn gvc = new GridViewColumn();

    gvc.Header="Column1";

    gvc.DisplayMemberBinding = new Binding("myDataTableColumn");

    gvc.Width=100;

    myGridView.Columns.Add(gvc);

     

    Binding bi = new Binding();

    myListView.DataContext = myDataTable;

    myListView.SetBinding(ListView.ItemsSourceProperty, bi);

     

     

    The datatable has 10.000 rows and 150 columns. When I bind all the 150 columns to the GridView the following happens:

     

    1) it takes more or less half a second to a second to display the data

    2) when I scroll horizontally (to the left or right), scrolling is done real-time with no delay at all (as it should)

    3) when I scroll vertically (up and down), scrolling has a delay of nearly one second! Using the scrollbar is awful, the use of the ListView is nearly impossible. (User will be nerved by that and chuck away my product...)

     

    When I use the same datatable and bind only 10 of the 150 columns to the GridView, the vertical scrolling is getting better. You can see a delay between the mouseposition and the viewport of the scrollbar when scrolling with leftmousebutton-down, but I could live with that (it´s not pretty, but...)

     

    Are there any possibilities to improve the performance of the ListView+GridView when using such a "big" datatable? (Ok, "big" in database application means another size ;-) this is really small compared to databases with millions of rows)

     

    Thanks in advance,

    SR912

    Tuesday, December 11, 2007 10:45 AM

Answers

  • User will be nerved by that and chuck away my product

     

    If I tried an application that presented me with a 10,000 x 150 table, I would chuck it away no matter how fast it scrolled. I cant imagine a situation where this amount of data is what the user really wants, because no human can absorb all that.

     

    In terms of rows of data, why not do one or both of these:

     

    1) Provide the data in pages of 20-50 items. If the data is sortable, what they want can usually be brought onto the top page or two.

     

    2) Provide a filter/search mechanism so the user can remove the data they are not interesting in.

     

    In terms of Columns, WPF offers you some very interesting ways to be innovative in your approach here. I am sure that of those 150 columns, some are more important that others, and there may well be logical groups of data, so think about some scheme to let the user filter columns too.

     

    If you requirements really are such that you need to do this, then i think you have some work to do. WPF has, and ListView already uses a VirtualizingStackPanel, that will only create the UI elements for visible data. This works on a row basis, and not a column basis. You could look to implement a further sub class of this to only virtualize UI elements for columns.

     

    Review how you are binding too. If its a read only view, see of BindingMode.OneTime works for you.

     

    There are a number of optimization guidelines here: http://msdn2.microsoft.com/en-gb/library/aa970683.aspx

     

    Regards,

    Nick.

     

     

    Tuesday, December 11, 2007 12:16 PM

All replies

  • User will be nerved by that and chuck away my product

     

    If I tried an application that presented me with a 10,000 x 150 table, I would chuck it away no matter how fast it scrolled. I cant imagine a situation where this amount of data is what the user really wants, because no human can absorb all that.

     

    In terms of rows of data, why not do one or both of these:

     

    1) Provide the data in pages of 20-50 items. If the data is sortable, what they want can usually be brought onto the top page or two.

     

    2) Provide a filter/search mechanism so the user can remove the data they are not interesting in.

     

    In terms of Columns, WPF offers you some very interesting ways to be innovative in your approach here. I am sure that of those 150 columns, some are more important that others, and there may well be logical groups of data, so think about some scheme to let the user filter columns too.

     

    If you requirements really are such that you need to do this, then i think you have some work to do. WPF has, and ListView already uses a VirtualizingStackPanel, that will only create the UI elements for visible data. This works on a row basis, and not a column basis. You could look to implement a further sub class of this to only virtualize UI elements for columns.

     

    Review how you are binding too. If its a read only view, see of BindingMode.OneTime works for you.

     

    There are a number of optimization guidelines here: http://msdn2.microsoft.com/en-gb/library/aa970683.aspx

     

    Regards,

    Nick.

     

     

    Tuesday, December 11, 2007 12:16 PM
  •  

    "If I tried an application that presented me with a 10,000 x 150 table, I would chuck it away no matter how fast it scrolled. I cant imagine a situation where this amount of data is what the user really wants, because no human can absorb all that."

     

    Maybe your imagination would also have you chuck Excel 2007 which allows 1,048,576 rows by 16,384 columns.

    Tuesday, December 11, 2007 4:17 PM
  • As it happens, Excel can also support spreadsheets of usefully small dimensions.

    Tuesday, December 11, 2007 5:01 PM
  • I am also binding dynamically a data table to a Listview/GridView for control historian.  There are not a lot of columns but can be a zillion points.   There is table view  Listview/GridView  and there also a graph that is the data graphed on another tab in tab control.    So basically there is time column and a few parameter values.   The first time through it works in decent speed dynmically binding but second it is very slow and finally finishes.  I am trying to use common WPF UI elements - not automate excel.  Any suggestions on a better way for perfomance and UI viewing ?  It works fine the first time for 30000 rows but then the second time is very slow - but works.  I've tried clear'in everything but have not had success.

    Thanks, Eric
    Thursday, October 01, 2009 1:37 AM
  • The solution I found was to create a new Listview every time.  Then performance is decent every time.

    Monday, December 07, 2009 11:08 PM