WMI query results to DataGrid
-
Saturday, March 03, 2012 9:37 AM
Hi,
I'm trying to get the results of a WMI to display in a datagrid however the code executes without error yet the datagrid doesnt show any output
Try Dim scope As New ManagementScope("\\" & servername & "\root\MicrosoftDFS") scope.Connect()
Dim query As New ObjectQuery("SELECT * FROM DfsrReplicatedFolderInfo") Dim searcher As New ManagementObjectSearcher(scope, query) Dim queryCollection As ManagementObjectCollection queryCollection = searcher.Get() DataGridView1.DataSource = queryCollection
For Each
queryObj As ManagementObject In searcher.Get() rtbOutput.AppendText(CStr(queryObj("ReplicationGroupName"))) Next
The WMI query is working as the data can be appended to a textbox.
Many thanks for your help
- Edited by RobbieOwens Saturday, March 03, 2012 9:39 AM
All Replies
-
Saturday, March 03, 2012 11:04 AM
Robbie, be aware you are not using a DataGrid, that is a complete different control (which has even more versions)
You are using a windows forms DataGridView which expect in its datasource an IBindinglist collection.
ManagementObjectCollection is a rather old collection not being that.
http://msdn.microsoft.com/en-us/library/system.management.managementobjectcollection.aspx
I'm not sure if the code on this page will do the job for you but I assume it does.
http://msdn.microsoft.com/en-us/library/bb341406.aspx
Success
Cor- Marked As Answer by RobbieOwens Wednesday, March 07, 2012 11:10 AM
-
Wednesday, March 07, 2012 11:10 AM
Robbie, be aware you are not using a DataGrid, that is a complete different control (which has even more versions)
You are using a windows forms DataGridView which expect in its datasource an IBindinglist collection.
ManagementObjectCollection is a rather old collection not being that.
http://msdn.microsoft.com/en-us/library/system.management.managementobjectcollection.aspx
I'm not sure if the code on this page will do the job for you but I assume it does.
http://msdn.microsoft.com/en-us/library/bb341406.aspx
Success
CorThanks for this Cor, I'm sure what your suggesting will work but I've changed the way the data is not presented so I not proceeding this way now but thanks for your help.
Cheers
Rob

