-1

I hava a DatagridView with a BindingSource with ~5000 DataItems comming from a LiteDB Source. Those DataItems have a little preview picture included.

My Problem and Question is: Can I improve the performance of the Databind somehow? Or do I using it wrong?

Here is my DataObject

public class VEFile
{
    public VEFile()
    {
        Tags = new List<VETag>();
    }
    public static DateTime LastPlaybacked { get; set; }

    public string Path { get; set; }
    public string FileName { get; set; }
    public string LastAccessed { get; set; }

    public byte[] Thumbnail { get; set; }
    public List<VETag> Tags { get; set; }
    [System.ComponentModel.Browsable(false)]
    public string Id { get; set; }
    public DateTime LastModified { get; set; }
    public long FileSize { get; set; }
    [BsonIndex]
    public int ViewCount { get; set; }
}

And my Databinding Code:

using (var db = new MyLiteDatabase(connectionString))
        {
            var filesCollection = db.GetCollection<VEFile>("files");

            var results = filesCollection.Include(x => x.Tags).FindAll().OrderByDescending(x => x.LastModified);

            originalBindingList = new BindingList<VEFile>(new List<VEFile>(results));
            bindingSource1.DataSource = originalBindingList.OrderByDescending(x => x.LastModified);
        }

The last Line

        bindingSource1.DataSource = originalBindingList.OrderByDescending(x => x.LastModified);

hangs up for several seconds plus the RAM Usage ramps up ~2GB and drops instantly after that.

Michele
  • 6,126
  • 2
  • 41
  • 45

1 Answers1

0

You need to use paging. The DataSource object will support this by setting TotalNumberOfItems, CurrentPageIndex, PageSize properties.

Then you will adjust your query to only select PageSize number of rows. Use the Take and Skip methods of LINQ.

matt-dot-net
  • 4,204
  • 21
  • 24