zoukankan
html css js c++ java
TreeView在显示大容量数据库数据时的使用
由于在利用
treeView
在显示大容量数据库数据时,使用递归算法非常费时,要求用户长时间的等待。那么如何在使用
treeView
显示大容量数据库数据时改善用户体验呢?
笔者使用用户自主选择的方法很好的解决了这一问题。
具体方法如下:
private
void
btnOpenData_Click(
object
sender, EventArgs e)
{
if
(openFileDialog1.ShowDialog()
==
DialogResult.OK)
{
//
获取数据源
datafilename
=
openFileDialog1.FileName;
string
constring
=
@"
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=
"
+
datafilename;
this
.lbltishi.ForeColor
=
Color.Red;
this
.lbltishi.Text
=
"
正在生成栏目资源目录……
"
;
this
.Refresh();
ds.Clear();
//
ds1.Clear();
OleDbConnection con
=
new
OleDbConnection();
try
{
con.ConnectionString
=
constring;
con.Open();
OleDbCommand cmd
=
new
OleDbCommand();
cmd.Connection
=
con;
cmd.CommandText
=
"
select * from tchannel order by channel_parentid
"
;
cmd.CommandType
=
CommandType.Text;
OleDbDataAdapter da
=
new
OleDbDataAdapter(cmd);
da.Fill(ds);
}
catch
(Exception ex)
{
throw
(ex);
}
finally
{
con.Close();
}
//
生成一级树目录
treeView1.Nodes.Clear();
TreeNode tn
=
new
TreeNode(
"
所有栏目资源
"
);
this
.treeView1.Nodes.Add(tn);
addtree(
"
0
"
, tn);
}
}
private
void
addtree(
string
ParentID, TreeNode pNode)
{
//
使用DataView提高用户体验,并在所有的同级子目录下都增加“请双击搜索子资源(XXXXX)”的下一级子目录,以便用户通过双击展开。
DataView dvtree
=
new
DataView(ds.Tables[
0
]);
dvtree.RowFilter
=
"
channel_parentid='
"
+
ParentID
+
"
'
"
;
foreach
(DataRowView row
in
dvtree)
{
TreeNode node
=
pNode.Nodes.Add(row[
"
channel_name
"
].ToString());
node.Nodes.Add(
"
请双击搜索子资源(
"
+
row[
"
channel_id
"
].ToString()
+
"
)
"
);
}
}
private
void
treeView1_NodeMouseDoubleClick_1(
object
sender, TreeNodeMouseClickEventArgs e)
{
//
从所双击的节点得到TREEVIEW
TreeView td
=
(TreeView)sender;
//
得到当前的节点
TreeNode tn
=
td.SelectedNode;
//
得到当前节点的父节点
TreeNode parenttn
=
tn.Parent;
//
从“请双击搜索子资源(channel_id)"中得到channel_id值,以便根据这个channel_id值在数据库中查找channel_parentid为此值的所有下一节点;
int
start
=
tn.Text.LastIndexOf(
"
(
"
);
int
end
=
tn.Text.LastIndexOf(
"
)
"
);
try
{
string
channelparentid
=
tn.Text.Substring(start
+
1
, end
-
start
-
1
);
//
如果找到值说明是双击的是“请双击搜索子资源(channel_id)”这一节点。
//
对这个节点应删除,以便添加新的子节点
tn.Remove();
addtree(channelparentid, parenttn);
}
//
否则就是一个已搜索出的有效的节点,对已搜索出的有效的节点,得到相应的数据资源路径,并在数据表中查询操作。
catch
(ArgumentOutOfRangeException ee)
{
//
得到当前节点的数据资源路径,并去掉0层上的“所有栏目资源\”,从而得到真正的数据资源路径。
try
{
this
.lblCurdata.Text
=
tn.FullPath.Substring(
7
);
string
channelid
=
this
.lblCurdata.Text;
bindgrid(channelid,typestring,
this
.dateTimePicker1.Value ,
this
.dateTimePicker2.Value);
//
查询数据操作
}
catch
(ArgumentOutOfRangeException ef)
{
this
.lblCurdata.Text
=
"
所有栏目
"
;
bindgrid(
"
-
"
, typestring,
this
.dateTimePicker1.Value,
this
.dateTimePicker2.Value);
}
}
}
查看全文
相关阅读:
joda-time的使用
logger 的使用一 小结
svn 技巧
mysql 获取一段时间的数据
Drools5
Java各种Utils小结
Java 8 新特新 工具类 ZonedDateTime
集合工具类CollectionUtils、ListUtils、SetUtils、MapUtils的使用
sonar 的使用
MySQL入门教学(看完必懂,图文详解!)
原文地址:https://www.cnblogs.com/ahuang1118/p/316513.html
最新文章
逆向分析攻于防之工具系列
xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
chrome标签整理
热门文章
关于POI相关通用方法源码
关于日期通用方法源码
关于字符串操作工具类源码
关于图片相关处理代码片段
分布式事务
GJ项目技术代码相关总结
关于项目中Spring版本与jdk1.8兼容问题解决
TCP/IP知识
设计模式
常用工具的依赖
Copyright © 2011-2022 走看看