I’m new to VB and I use the below code to collect local disk drive info, is there a way to store the collected information in a single text box instead of having tables and DataGridView.

Public Function getLogicalDriveStructure() As DataTable
        Dim dt As New DataTable
        dt.Columns.Add(New DataColumn("Description"))
        dt.Columns.Add(New DataColumn("DeviceID"))
        dt.Columns.Add(New DataColumn("FileSystem"))
        dt.Columns.Add(New DataColumn("FreeSpace"))
        dt.Columns.Add(New DataColumn("Name"))
        dt.Columns.Add(New DataColumn("Size"))

        Return dt
    End Function

Public Sub addLogicalDrive(ByRef dt As DataTable, ByVal Description As String, ByVal DeviceID As String, ByVal FileSystem As String, ByVal FreeSpace As String, ByVal Name As String, ByVal Size As String)
        Dim dr As DataRow
        dr = dt.NewRow
        dr("Description") = Description
        dr("DeviceID") = DeviceID
        dr("FileSystem") = FileSystem
        dr("FreeSpace") = FreeSpace
        dr("Name") = Name
        dr("Size") = Size
    End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim searcher As New Management.ManagementObjectSearcher( _
             "root\CIMV2", "SELECT * FROM Win32_LogicalDisk")
            Dim dt As DataTable = getLogicalDriveStructure()
            For Each queryObj As ManagementObject In searcher.Get()
                addLogicalDrive(dt, queryObj("Description"), queryObj("DeviceID"), queryObj("FileSystem"), Convert.ToString(queryObj("FreeSpace")), queryObj("Name"), Convert.ToString(queryObj("Size")))
            DataGridView1.DataSource = dt
        Catch err As ManagementException
            MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
        End Try

    End Sub

You could start off by using the System.IO namespace of the .NET Framework. What is the purpose of storing all that info in textbox? You could store some sort of a unique identifier as the value of the textbox and then when a user selects something from the textbox, showw the details of the drive[object] that they selected.

This article has been dead for over six months. Start a new discussion instead.