网络安全

位置:IT落伍者 >> 网络安全 >> 浏览文章

掌握和使用 TreeView 加载数据


发布日期:2023年02月22日
 
掌握和使用 TreeView 加载数据
TreeView控件在编制程序过程中用得比较多正确的掌握和使用这个控件可以很好的表示层次关系的数据在数据库应用系统中我们可以用TreeView来显示树形结构如显示目录树显示班级信息等等有着很重要的作用看看下面一个实际的问题每个年度都有许多的班级将这些数据层次表示数据库:access表:Test字段:bh(班级编号文本主键)nj(年级文本)功能以层次关系表现出数据测试数据 添加TreeView控件个按钮个按钮分别用了两种方法显示数据但是第二种方法明显优于第一种可以仔细的看代码引用microsoft activex data object x libraryDim nddata As NodeDim cnn As ADODBConnectionDim rs As New ADODBRecordsetDim rs As New ADODBRecordsetPrivate Sub Command_Click()On Error Resume NextSet nddata = TreeViewNodesAdd( db 班级信息)nddataExpanded = TrueDim intcount As IntegerDim inttable As IntegerDim intfield As IntegerDim intfn As IntegerrsOpen select nj from test group by nj cnn inttable = rsRecordCountDo While inttable intcountSet nddata = TreeViewNodesAdd(db tvwChild F & rsFields(nj) rsFields(nj))rsOpen select bhnj from test where nj= & rsFields(nj) & cnn intfield = rsRecordCountIf intfield Thenintfn = Do While intfield intfnSet nddata = TreeViewNodesAdd(F & rsFields(nj) tvwChild S & rsFields(bh) rsFields(bh))rsMoveNextintfn = intfn + LoopEnd IfrsClosersMoveNextintcount = intcount + LooprsCloseEnd Sub第二种方法Private Sub Command_Click()On Error Resume NextSet nddata = TreeViewNodesAdd( db 班级信息)nddataExpanded = TruersOpen select * from test cnn Do While Not rsEOFIf ca rsFields(nj) ThenSet nddata = TreeViewNodesAdd(db tvwChild F & rsFields(nj) rsFields(nj))ca = rsFields(bb)End IfSet nddata = TreeViewNodesAdd(F & rsFields(nj) tvwChild S & rsFields(bh) rsFields(bh))rsMoveNextLooprsCloseEnd SubPrivate Sub Form_Load()Set cnn = New ADODBConnectioncnnOpen Provider=MicrosoftJetOLEDB;Data Source=F:\csdn_vb\database\treeview的节点添加\\testmdbEnd SubPrivate Sub Form_Unload(Cancel As Integer)Set con = NothingEnd Sub

上一篇:轻松玩转远程桌面之高手运用

下一篇:命令行模式修改文件夹的访问及共享权限