PowerSNMP for .NET
Populate Method (VariableList)
Example 




The TreeView object to populate.
The root Oid of the variable tree.
A sorted collection of MibNode objects used to populate the treeView.
Populates a TreeView from the VariableList. Available in .NET Framework only.
Syntax
Public Sub Populate( _
   ByVal treeView As TreeView, _
   ByVal rootOid As String, _
   ByVal mibNodes As MibNodes _
) 
Dim instance As VariableList
Dim treeView As TreeView
Dim rootOid As String
Dim mibNodes As MibNodes
 
instance.Populate(treeView, rootOid, mibNodes)
public void Populate( 
   TreeView treeView,
   string rootOid,
   MibNodes mibNodes
)
public: void Populate( 
   TreeView* treeView,
   string* rootOid,
   MibNodes* mibNodes
) 
public:
void Populate( 
   TreeView^ treeView,
   String^ rootOid,
   MibNodes^ mibNodes
) 

Parameters

treeView
The TreeView object to populate.
rootOid
The root Oid of the variable tree.
mibNodes
A sorted collection of MibNode objects used to populate the treeView.
Remarks

This function populates a TreeView with the Variables in the VariableList using the rootOid as the root TreeNode. Variables are represented as leaves in the tree.

To use images for the node, set the treeView's ImageList property to an ImageList with the following image indices:

0 = leaf, 1 = selected leaf, 2 = branch, 3 = selected branch

Each TreeNode.Tag corresponding to a Variable will contain the Variable.

Example
The following example demonstrates how to walk a MIB and display the response variables.
private void button1_Click(object sender, EventArgs e)
{
    //Perform MIB walk on a worker thread
    manager1.Start(walkMib, manager1.Mib.GetByNodeName(NodeName.system).Oid);
}

private void walkMib(SnmpSocket managerSocket, object state)
{
    //The state contains the OID to walk (in this case, the system group)
    string oid = state as string;

    //Walk the MIB from the specified root OID
    VariableList variables = managerSocket.Walk(oid, myAgentAddress);

    //Marshal variables returned to the UI thread using the Walk event
    manager1.Marshal(oid, variables, "", null);
}

private void manager1_Walk(object sender, WalkEventArgs e)
{
    //Populate a treeview control with the returned variables
    e.Variables.Populate(tvwVariables, e.Oid, manager1.Mib);
}
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
    'Perform MIB walk on a worker thread
    manager1.Start(AddressOf walkMib, manager1.Mib.GetByNodeName(NodeName.system).Oid)
End Sub

Private Sub walkMib(ByVal managerSocket As SnmpSocket, ByVal state As Object)
    'The state contains the OID to walk (in this case, the system group)
    Dim oid As String = TryCast(state, String)

    'Walk the MIB from the specified root OID
    Dim variables As VariableList = managerSocket.Walk(oid, myAgentAddress)

    'Marshal variables returned to the UI thread using the Walk event
    manager1.Marshal(oid, variables, "", Nothing)
End Sub

Private Sub manager1_Walk(ByVal sender As Object, ByVal e As WalkEventArgs)
    'Populate a treeview control with the returned variables
    e.Variables.Populate(tvwVariables, e.Oid, manager1.Mib)
End Sub
See Also

Reference

VariableList Class
VariableList Members


PowerSNMP for .NET Documentation Version 8.0
© 2024 Dart Communications. All Rights Reserved.
Send comments on this topic