画出来比较好,用鼠标当前坐标位置进行计算选择的方格位置,如果一个方格用一个控件,会很浪费资源。
创新互联服务项目包括文成网站建设、文成网站制作、文成网页制作以及文成网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,文成网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到文成省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!
'通过过System.IO.DirectoryInfo对象可以查阅目录信息,下面是遍历一个文件夹下所有层次的子文件夹,如果只检查下一层目录就更简单了。
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim folder = New System.IO.DirectoryInfo("D:\Documents")
Dim items = getemptyfolder(folder)
For Each item In items
Console.WriteLine(item.FullName)
Next
End Sub
Function getemptyfolder(ByVal folder As System.IO.DirectoryInfo) As System.IO.DirectoryInfo()
Dim items As New List(Of System.IO.DirectoryInfo)
If folder.EnumerateFiles().Count = 0 Then
items.Add(folder)
End If
Dim subfolders = folder.EnumerateDirectories()
For Each subfolder In subfolders
items.AddRange(getemptyfolder(subfolder)) '查询树形目录结构类型数据用递归法实现
Next
Return items.ToArray()
End Function
'还是学c#语言吧,我发觉同样一个数组,c#功能多的多,vb点虐 没几条方法可用。
这种不要用递归,知道关键字长度,知道节数用判断就可以了,取前3位第一节,第二节取3个为父节点,取全部为第二节关键字,第三节取前6个为父节点,取全部为第三节关键字.
并没有要求培养字段,查询时从len(ID)=3*N,每次循环时N都+1
select * from tablename where len(id)=3
select case N
case 1
treeview.node.add id,name
case 2
treeview.node(left(id,3)).node.add id,name
case 3
treeview.node(left(id,3)).node(left(id,6)).add id,name
end select
查询结果排个升序就不会存在这样的问题了,你刚才说的那种,如果中间没有比001001001001001更短的关键字,那么就脱节,这种是不可能添加到treeview中.
递归一般用在不知道节数,没有关键字的情况,比如系统目录结构.
递归整个C盘目录:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim iDir As IO.Directory
Dim node As New TreeNode
'先把C盘添加到树中
TreeView1.Nodes.Clear()
node.ImageIndex = 0
node.Text = "本地磁盘 C:"
node.SelectedImageIndex = -1
TreeView1.Nodes.Add(node)
Dim i As Integer
'获取C:盘根目录下的文件夹
Dim str() As String = IO.Directory.GetDirectories("D:\")
For i = 0 To str.GetUpperBound(0)
'调用遍历过程
AddDirectory("C:", str(i), node)
Next
node = Nothing
iDir = Nothing
End Sub
Public Sub AddDirectory(ByVal strFatherPath As String, ByVal strPath As String, ByVal nodeFather As TreeNode)
Dim iDir As IO.Directory
'Dim iDirInfo As IO.DirectoryInfo
Dim i As Integer
Dim node As New TreeNode
'先添加本目录,从文件夹路径分析出文件夹名称
node.Text = Strings.Replace(strPath, strFatherPath "\", "", , 1)
'为单个节点指定节点未被选中时显示的图标
node.ImageIndex = 1
'为单个节点指定节点被选中时显示的图标
node.SelectedImageIndex = 2
nodeFather.Nodes.Add(node)
Application.DoEvents()
Try
Dim str() As String = IO.Directory.GetDirectories(strPath)
'遍历该目录的子文件夹
For i = 0 To str.GetUpperBound(0)
AddDirectory(strPath, str(i), node)
Next
Catch ex As Exception
Debug.WriteLine(ex.Message)
End Try
node = Nothing
iDir = Nothing
End Sub