Results 1 to 4 of 4

Thread: Populating a data grid

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2006
    Posts
    250

    Populating a data grid

    Hi everyone,

    I am trying to populate my datagrid (name: GridLocalDisk) with data from a WMI query.

    I have three columns within my data grid (Drive, diskSize, and Remaining)

    How would I populate each "DeviceID" into the "Drive" column?
    How would I populate each "Size" into the "diskSize" column?
    How would I populate each "FreeSpace" into the "Remaining" column?

    Below is my WMI code. I currently have the data outputting to a listbox (ListBox3).

    Any help would be greatly appreciated.

    Code:
        Function SetBytes(ByVal Bytes) As String
            SetBytes = Format(Bytes / 1024 / 1024 / 1024, "#0.00") & " GB"
        End Function
    
    Private Sub btnQueryMachine_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQueryMachine.Click
    
            Dim manScope As ManagementScope
            Dim manPath As ManagementPath
            Dim manClass As ManagementClass
            Dim manObj As ManagementObject
            Dim manObjCol As ManagementObjectCollection
            Dim output As String = String.Empty
            Dim RemoteMachineName As String
    
            RemoteMachineName = "COMPUTERNAME"
    
            Try
    
                manPath = New ManagementPath("\\" & RemoteMachineName & "\root\CIMV2:Win32_LogicalDisk")
                manScope = New ManagementScope(manPath)
    
                'Since it is a remote system, you must provide proper credentials to access it
    
                'manScope.Options.Username = "yourDomainName\administrator"
                'manScope.Options.Password = "yourPassword"
                manClass = New ManagementClass(manScope, manPath, Nothing)
                manObjCol = manClass.GetInstances()
    
                For Each manObj In manObjCol
                    If (manObj("Description").ToString) = "Local Fixed Disk" Then
                        ListBox3.Items.Add(manObj("DeviceID").ToString)
                        ListBox3.Items.Add(SetBytes(manObj("Size").ToString))
                        ListBox3.Items.Add(SetBytes(manObj("FreeSpace").ToString))
                    End If
                Next
    
                ' MessageBox.Show(output)
            Catch ex As Exception
                ' MessageBox.Show(ex.Message)
            Finally
                manPath = Nothing
                manScope = Nothing
                manClass = Nothing
                manObjCol = Nothing
            End Try
        End Sub

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Jun 2006
    Posts
    250

    Re: Populating a data grid

    I have still been doing some research, but I can not figure out how to populate this data.... hmmmmmmmm



    any suggestions?

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2006
    Posts
    250

    Re: Populating a data grid

    Is what I am doing even possible using a datagrid? If not, is there an equivalent item I can use and get the same desired end results?

  4. #4
    Addicted Member Abrium's Avatar
    Join Date
    Feb 2007
    Location
    The Great State of Texas
    Posts
    205

    Re: Populating a data grid

    MSDN on How To: Datagrid. Best I can do for ya GF.
    Abrium
    Asking the beginners questions so you don't have to!
    If by chance hell actually froze over and I some how helped you... Please rate.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width