缓慢的数据绑定-LinqToXML到DataGridView [英] Slow data binding - LinqToXML to DataGridView

查看:117
本文介绍了缓慢的数据绑定-LinqToXML到DataGridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

将Linq查询结果分配给DataGrid数据源需要花费大量时间(40秒),而XML文件中只有8000个条目(行).我知道可以通过遍历Linq结果元素并将它们逐个添加到网格视图中来解决此问题,但是您想到的还有其他简便方法吗?

在此先感谢

Hey Guys,

Assigning the Linq query result to the DataGrid datasource it takes a lot of time (40 seconds) and I only have 8000 entries (rows)in the XML file. I know that this can be fixed by looping through the Linq result elements and adding them to the grid view one by one but is there any other easy way that comes to your mind?

Thanks in advance

var Log =
    from c in xmlDoc.Descendants("Event")
    select new
    {
        Type = ((string)c.Element("Type").Value),
        Class = ((string)c.Element("Class").Value),
        Method = ((string)c.Element("Method").Value),
        DateTime = ((string)c.Element("DateTime").Value),
        Text = ((string)c.Element("Text").Value),
        StackTrace = ((string)c.Element("StackTrace").Value),
        SourceTable = ((string)c.Element("SourceTable").Value),
        SourceField = ((string)c.Element("SourceField").Value),
        SourceValue = ((string)c.Element("SourceValue").Value),
        TargetTable = ((string)c.Element("TargetTable").Value)
    };

dbGridLog.AutoGenerateColumns = true;
dbGridLog.DataSource = Log.ToList();

推荐答案

设置AutoSizeColumnsMode = False; &AutoSizeRowsMo​​de = False;解决了.现在它在2秒钟内加载10000条记录!
Setting t he AutoSizeColumnsMode = False; & AutoSizeRowsMode = False; solved it. Now it loads 10000 records in 2 seconds!


这篇关于缓慢的数据绑定-LinqToXML到DataGridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆