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

Submitted by: 
Visitors have accessed this post 380 times.

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.
drives321

Step 2

Do the Form just like shown below.
drive123

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.  
  18. End If
  19. Select Case drive.DriveType
  20. Case IO.DriveType.Fixed : driveType = "Local Disk"
  21. Case IO.DriveType.CDRom : driveType = "CD-ROM"
  22. Case IO.DriveType.Network : driveType = "Network Drive"
  23. Case IO.DriveType.Removable : driveType = "Removable Disk"
  24. End Select
  25. ListView1.Items.Add(drivename)
  26. ListView1.Items(inc).SubItems.Add(driveltr)
  27. ListView1.Items(inc).SubItems.Add(driveType)
  28. inc += 1
  29. Next
  30. 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.


Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.