Hard Drive Space Values into Datagrid as columns

I am looking to get the hard drives and spaces from my servers and have the below working great to return it via an array - but wanted to do return each  value as a column in a datagrid - is this possible and if so how?
--------------------
    Private Function SystemList(ByVal strComputer As String) As ArrayList

        Dim al2 As New ArrayList
        Dim co As ConnectionOptions = New ConnectionOptions()
        co.Username = "Nsadm13"
        co.Password = "houston"
        Dim ms As System.Management.ManagementScope = New System.Management.ManagementScope("\\" & strComputer & "\root\cimv2", co)
        Dim oq As System.Management.ObjectQuery = New System.Management.ObjectQuery("Select * from Win32_LogicalDisk where DriveType=3")
        Dim Query1 As ManagementObjectSearcher = New ManagementObjectSearcher(ms, oq)
        Dim queryCollection1 As ManagementObjectCollection = Query1.Get()
        Dim mo As ManagementObject

        For Each mo In queryCollection1
            al2.Add( _
             "<b>Drive</b>: " & mo("Name").ToString() & _
                        "<br><b>Free Space</b>: " & Data.ConvertBytes(CType(mo("FreeSpace").ToString, Long)) & _
                        "<br><b>Size</b>: " & Data.ConvertBytes(CType(mo("Size").ToString, Long)) _
                       )
        Next
        Return (al2)

    End Function
tbaseflugAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RonaldBiemansCommented:
Instead of using an arraylist use a datatable
0
tbaseflugAuthor Commented:
Any way that you could show me based upon my code above?
0
RonaldBiemansCommented:
Private Function SystemList(ByVal strComputer As String) As datatable

        Dim al2 As New datatable
        al2.columns.add("Diskname", gettype(System.string))
        al2.columns.add("FreeSpace", gettype(System.int32))
        al2.columns.add("Size", gettype(System.int32))

        Dim co As ConnectionOptions = New ConnectionOptions()
        co.Username = "Nsadm13"
        co.Password = "houston"
        Dim ms As System.Management.ManagementScope = New System.Management.ManagementScope("\\" & strComputer & "\root\cimv2", co)
        Dim oq As System.Management.ObjectQuery = New System.Management.ObjectQuery("Select * from Win32_LogicalDisk where DriveType=3")
        Dim Query1 As ManagementObjectSearcher = New ManagementObjectSearcher(ms, oq)
        Dim queryCollection1 As ManagementObjectCollection = Query1.Get()
        Dim mo As ManagementObject

        For Each mo In queryCollection1
dim dr as datarows = dt.newrow
dr.item("Diskname") = mo("Name").ToString()
dr.item("FreeSpace") = Data.ConvertBytes(CType(mo("FreeSpace").ToString, int32))
dr.item("Size") = Data.ConvertBytes(CType(mo("Size").ToString, int32))
dt.rows.add(dr)
        Next
        Return (al2)

    End Function
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

tbaseflugAuthor Commented:
RonaldBiemans -

That works great!!!  However, is there any way to flip it so that the drives appear across the top as column headers and that the size and space columns are rows under then., e.g.

C     D     E
---   ---   ---
10   15   20
0
RonaldBiemansCommented:
Hmmm, there is but you have to do a bit of cheating, The trick is to transpose your datatable.

Can this wait till tomorrow because I have to leave now, but I can give you the code first thing in the morning



0
tbaseflugAuthor Commented:
Certainly - I just appreciate the help!
0
RonaldBiemansCommented:
Hi tbaseflug, try this


Private Function SystemList(ByVal strComputer As String) As datatable

        Dim dt As New datatable
        dt.columns.add("Diskname", gettype(System.string))
        dt.columns.add("FreeSpace", gettype(System.int32))
        dt.columns.add("Size", gettype(System.int32))

        Dim co As ConnectionOptions = New ConnectionOptions()
        co.Username = "Nsadm13"
        co.Password = "houston"
        Dim ms As System.Management.ManagementScope = New System.Management.ManagementScope("\\" & strComputer & "\root\cimv2", co)
        Dim oq As System.Management.ObjectQuery = New System.Management.ObjectQuery("Select * from Win32_LogicalDisk where DriveType=3")
        Dim Query1 As ManagementObjectSearcher = New ManagementObjectSearcher(ms, oq)
        Dim queryCollection1 As ManagementObjectCollection = Query1.Get()
        Dim mo As ManagementObject

        For Each mo In queryCollection1
             dim dr as datarows = dt.newrow
             dr.item("Diskname") = mo("Name").ToString()
             dr.item("FreeSpace") = Data.ConvertBytes(CType(mo("FreeSpace").ToString, int32))
             dr.item("Size") = Data.ConvertBytes(CType(mo("Size").ToString, int32))
             dt.rows.add(dr)
        Next

        Dim dt2 As New DataTable
        dt2.Columns.Add("Diskinfo")
        For Each dr2 As DataRow In dt.Rows
            dt2.Columns.Add(dr2.Item("Diskname"), GetType(System.String))
        Next


        For i As Integer = 1 To dt.Columns.Count - 1
            Dim dr2 As DataRow = dt2.NewRow
            dr2(0) = dt.Columns(i).ColumnName
            For r As Integer = 0 To dt.Rows.Count - 1
                dr2(r + 1) = dt.Rows(r).Item(i)
            Next
            dt2.Rows.Add(dr2)
        Next
        Return (dt2)

    End Function
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tbaseflugAuthor Commented:
RonaldBiemans -

Wow, that works great!!! You have certainly earned the points.  I am going to open another 500 pt question as I have a list of server names coming from my SQL db and am looping through the server names in a datareader and will need to add the server name to the grid as well - you have earned the pts for this one and will certyainly give another 500 if you want to help on the last part of this?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.