9

使用 VB.Net 是否可以在下拉列表中列出所有映射的网络目录/驱动器?

我已经护目镜,但找不到任何有用的东西..

4

2 回答 2

7

要将其添加到 DropDownList:

 Private Sub TestCase1()
        Dim drive As System.IO.DriveInfo

    For Each drive In System.IO.DriveInfo.GetDrives()
        If drive.DriveType = IO.DriveType.Network Then
            DropDownList1.Items.Add(drive.Name)
        End If
    Next
End Sub

这就是我在 C# 中的做法:

private void TestCase1()
    {

        //Recurse through the drives on this system and add them to the new DropDownList DropDownList1 if they are a network drive.
        foreach(System.IO.DriveInfo drive in System.IO.DriveInfo.GetDrives())
        {
            //This check ensures that drive is a network drive.
            if (drive.DriveType == System.IO.DriveType.Network)
            {
                //If the drive is a network drive we add it here to a combobox.
                DropDownList1.Items.Add(drive);
            }
        }
    }
于 2012-10-02T11:29:48.957 回答
1

迈克有一个很好的答案,我会添加一些东西来防止它在每次点击打开时增长。说得好.... VB 中的组合框。

    Dim drive As System.IO.DriveInfo

If DropDownList1.Count < 1

     For Each drive In System.IO.DriveInfo.GetDrives()

         If drive.DriveType = IO.DriveType.Network Then

             DropDownList1.Items.Add(drive.Name)

         End If
     Next
End If
于 2015-09-29T18:01:44.173 回答