• We just launched and are currently in beta. Join us as we build and grow the community.

How to Display All Drives into the ListView Using VB.Net

agamemnon12

Cloud Innovator
A Rep
0
0
0
Rep
0
A Vouches
0
0
0
Vouches
0
Posts
122
Likes
17
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 400 XP
This tutorial that I’m going to teach you is about how to display all drives into the listview using Vb.Net. This method is useful when you have to display the computer drives in the listview. With this, you will be able to see and have an idea what drives are available on your computer. Simply follow the instructions below and you will be done in no time.

Creating Application

Step 1

Open Microsoft Visual Studio 2015 and create a new windows form application.
creating-application_7.png

Step 2

Do the Form just like shown below.
2018-11-16.png

Step 3

Go to the code view, create a sub procedure for retrieving all drives.
  1. Private

    Sub

    retrieveDrives()
  2. ListView1.Items.Clear()
  3. Dim

    inc As

    Integer

    = 0
  4. For

    Each

    drive As

    IO.DriveInfo In

    IO.DriveInfo.GetDrives
  5. Dim

    drivename As

    String

    = drive.Name
  6. Dim

    driveType As

    String

    = ""
  7. Dim

    driveltr As

    String

    = drive.Name
  8. If

    drive.IsReady AndAlso drive.VolumeLabel <> ""

    Then
  9. drivename = drive.VolumeLabel
  10. Else
  11. Select

    Case

    drive.DriveType
  12. Case

    IO.DriveType.Fixed : drivename = "Local Disk"
  13. Case

    IO.DriveType.CDRom : drivename = "CD-ROM"
  14. Case

    IO.DriveType.Network : drivename = "Network Drive"
  15. Case

    IO.DriveType.Removable : drivename = "Removable Disk"
  16. End

    Select

  17. End

    If
  18. Select

    Case

    drive.DriveType
  19. Case

    IO.DriveType.Fixed : driveType = "Local Disk"
  20. Case

    IO.DriveType.CDRom : driveType = "CD-ROM"
  21. Case

    IO.DriveType.Network : driveType = "Network Drive"
  22. Case

    IO.DriveType.Removable : driveType = "Removable Disk"
  23. End

    Select
  24. ListView1.Items.Add(drivename)
  25. ListView1.Items(inc).SubItems.Add(driveltr)
  26. ListView1.Items(inc).SubItems.Add(driveType)
  27. inc += 1
  28. Next
  29. End

    Sub

Step 4

Double click the button and call the method that you have created to execute when the button is clicked.
  1. Private

    Sub

    Button1_Click(sender As

    Object

    , e As

    EventArgs) Handles Button1.Click
  2. retrieveDrives()
  3. End

    Sub

For more question about this article. You can contact me @
Email – [email protected]
Mobile No. – 09305235027 – TNT
FB Account – https://www.facebook.com/onnaj.soicalap
Or feel free to comment below.

 

452,292

323,348

323,357

Top