c# WPF 项目优化
2024-09-12 06:49:35
业务流程图
优化前后对比:
优化过程:
1. 界面刷新,特别是表格刷新
把ListView.DataContext = DataSet 这些代码替换成以下:
public static void SetDataSource(ListView lv, DataSet ds)
{
DataSet preds = (DataSet)lv.DataContext;
if (preds == null) // first set datacontext
{
preds = ds;
lv.DataContext = preds;
}
else // reset data context, we don't change the datacontext object , but change data rows
{
DataTable tb = preds.Tables[0];
tb.Clear();
tb.Dispose();
foreach (DataRow dr in ds.Tables[0].Rows)
{
tb.ImportRow(dr);
}
lv.DataContext = preds;
ds.Dispose();
ds = null;
}
} public static void AddDataRowToDataSource(ListView lv, DataRow dr)
{
DataSet ds = (DataSet)lv.DataContext;
if (ds == null)
{
return;
}
else
{
DataTable tb = ds.Tables[0];
tb.ImportRow(dr);
lv.DataContext = ds;
}
}
2. 尽量减少 new 的使用
最新文章
- word
- c语言中类型隐性转换的坑
- href链接的地址
- [tp3.2.1]查询(2)
- matlab 函数说明--waitforbuttonpress
- [转]将某个Qt4项目升级到Qt5遇到的问题
- python核心编程-第五章-个人笔记
- DDD分层架构之值对象(介绍篇)
- Linux_服务器_01_查看公网IP
- 关于pocsuite的使用
- 在Android studio模拟器中运行apk文件
- 关于library cache lock和row cache lock产生的常见原因
- 电商门户网站商品品类多级联动SpringBoot+Thymeleaf实现
- 使用 idea 产生错误The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized
- scrapy的Middleware
- Codeforces Round #512 E - Vasya and Good Sequences
- MyBatis基础入门《十八》动态SQL(if-where)
- BroadcastReceiver(广播)的静态注册和动态注册 --Android开发
- [python] 私有变量和私有方法
- linux设置开机同步时间
热门文章
- Wcf资料收集
- CentOS 5.5 Samba服务器安装总结
- 在birt中解决引用了不存在的绑定出现的问题
- ORA-19502: write error on file ";/u01/app/oracle/oradata/standby/system01.dbf";, blockno 40321 (blocksize=8192)【error收集】
- PHP Sessions
- nat123 与微信公众号开发者测试账号配合调试
- explicit 关键字
- sqoop 1.4.4-cdh5.1.2快速入门
- DropdownList控件绑定数据源显示system.data.datarowview的问题
- HTML5+Css3-webkit-filter