다음을 통해 공유


How to Use Objects Passed to a Configuration Manager Console View

Applies To: System Center Configuration Manager 2007, System Center Configuration Manager 2007 R2, System Center Configuration Manager 2007 R3, System Center Configuration Manager 2007 SP1, System Center Configuration Manager 2007 SP2

To use Microsoft System Center Configuration Manager 2007 objects passed to a Configuration Manager console view, you use the IResultObject available from the SmsFormViewBase derived class implemented in the view.

The following procedure displays the instance properties of the Configuration Manager 2007 classes in a DataGridView control.

Before starting this procedure, you must perform the procedures in the following topics:

After you have built and deployed the project, start the Configuration Manager console. In the Namespace node under Tools you should see the namespace classes listed. Click a class and the view is displayed. If there are instances of the class, you can see their properties, in the DataGridView control, by using the UpDownControl control.

To display instance properties in a DataGridView

  1. In Solution Explorer, using the Visual Studio solution that you created in the How to Create a Configuration Manager Console View topic, right-click the file, ConfigMgrObjectsControl.cs, and then click View Designer.

  2. In the Toolbox, click the Common Controls tab, and then double-click NumericUpDown. A NumericUpDown control named numericUpDown1 is added to your control on the User Control Designer.

  3. In the Toolbox, click the Data tab, and then double-click DataGridView. A DataGridView control named dataGridView1 is added to your control on the User Control Designer. You might want to increase the size of the DataGridView control.

  4. To initialize the NumericUpDown control and the DataGridView control, add the following method to the ConfigMgrObjectsControl class:

    public override void PostInitialize()
    {
        try
        {
            IResultObject selectedClass = Node.ResultObject as IResultObject;
            dataGridView1.Columns.Add("Name", "Name");
            dataGridView1.Columns.Add("Value", "Value");
            IResultObject queryResults = selectedClass.ConnectionManager.QueryProcessor.ExecuteQuery("SELECT * FROM " + selectedClass.ObjectClass);
    
            numericUpDown1.Minimum = 0;
            int count = 0;
            foreach (IResultObject obj in queryResults)
            {
                count++;
            }
    
            numericUpDown1.Maximum = count;
        }
        catch (SmsException eX)
        {
            DialogHelper.ShowMessageBox("Couldn't initialize the view properly " + eX.Message);
    
        }
    }
    
  5. Double-click NumericUpDown. The selection change event handler, numericUpDown1_ValueChanged is added.

  6. To update the DataGridView control, after the NumericUpDown control is selected, add the following code to numericUpDown1_ValueChanged:

    try
    {
        IResultObject selectedClass = Node.ResultObject as IResultObject;
        IResultObject queryResults = selectedClass.ConnectionManager.QueryProcessor.ExecuteQuery("SELECT * FROM " + selectedClass.ObjectClass);
        int count = (int)numericUpDown1.Value;
        int pos = 1;
        dataGridView1.Rows.Clear();
    
        foreach (IResultObject obj in queryResults)
        {
            if (pos == count)
            {
                Dictionary<string, string> properties = obj.PropertyList;
    
                foreach (string property in properties.Keys)
                {
                    DataGridViewRowCollection row = new DataGridViewRowCollection(dataGridView1);
                    int position = dataGridView1.Rows.Add(row);
                    dataGridView1.Rows[position].Cells["Name"].Value = property;
                    dataGridView1.Rows[position].Cells["Value"].Value = properties[property];
                }
                break;
            }
            pos++;
        }
    }
    catch (SmsException ex)
    {
        DialogHelper.ShowMessageBox("Couldn't update the grid view " + ex.Message);
    
    }
    

Deploy the Assembly

This procedure builds the assembly you have created and copies it to the Configuration Manager console assemblies folder. For important information about deploying Configuration Manager console extensions, see Configuration Manager Console Extension Deployment.

To deploy the dialog box assembly

  1. Build the project, and depending on where you created your project, the assembly should be created as \Visual Studio 2005\Projects\ConfigMgrControl\ConfigMgrObjectsControl\bin\Debug\ConfigMgrObjectsControl.dll.

  2. Copy the assembly to the folder %ProgramFiles%\Microsoft Configuration Manager\AdminUI\bin.

See Also

Concepts

About Configuration Manager Console Views
How to Create a Configuration Manager Console View
How to Create Node XML for a Configuration Manager Console View