我有一个程序,它有一个带有两个组合框和两个文本框的datagridview。第一个组合框包含OID,另一个组合框包含SNMP操作(Get& GetNext)。 现在我想在我的OID的Combobox旁边添加另一个ComboBox,其中包含OID的描述(如sysDescr的1.3.6.1.2.1.1.1.0等),以及New ComboBox的值(具有OID描述的值) )当用户更改第一个组合框中的OID时自动更改。可能吗?如果是,那怎么样? 这是代码: 进口系统 进口SnmpSharpNet
Public Class Form1 Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object,ByVal e As System.Windows.Forms.DataGridViewCellEventArgs)处理DataGridView1.CellContentClick
End Sub
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
DataGridView1.Columns.Add("NameOne", "Column One")
DataGridView1.Columns.Add("NameTwo", "Column Two")
Dim dataGridRow As New DataGridViewRow()
Dim cells As DataGridViewCell() = New DataGridViewCell(1) {}
Dim txt1A As New DataGridViewTextBoxCell()
Dim txt1B As New DataGridViewTextBoxCell()
txt1A.Value = "Host"
txt1B.Value = "115.186.118.130"
dataGridRow.Cells.Add(txt1A)
txt1A.[ReadOnly] = True
dataGridRow.Cells.Add(txt1B)
dataGridRow.Height = 20
DataGridView1.Rows.Add(dataGridRow)
dataGridRow = New DataGridViewRow()
cells = New DataGridViewCell(1) {}
Dim txt2A As New DataGridViewTextBoxCell()
Dim cbo1 As New DataGridViewComboBoxCell()
cbo1.Items.Add("1.3.6.1.2.1.1.1.0")
cbo1.Items.Add("1.3.6.1.2.1.1.2.0")
cbo1.Items.Add("1.3.6.1.2.1.1.3.0")
cbo1.Items.Add("1.3.6.1.2.1.1.4.0")
cbo1.Items.Add("1.3.6.1.2.1.1.5.0")
cbo1.Value = cbo1.Items(0)
cbo1.[ReadOnly] = False
txt2A.Value = "OIDs"
dataGridRow.Cells.Add(txt2A)
txt2A.[ReadOnly] = True
dataGridRow.Cells.Add(cbo1)
dataGridRow.Height = 20
DataGridView1.Rows.Add(dataGridRow)
Dim requestOid() As String
requestOid = New String() {cbo1.Selected}
dataGridRow = New DataGridViewRow()
cells = New DataGridViewCell(1) {}
Dim txt3A As New DataGridViewTextBoxCell()
Dim cbo2 As New DataGridViewComboBoxCell()
cbo2.Items.Add("Get")
cbo2.Items.Add("GetNext")
cbo2.Value = cbo2.Items(0)
cbo2.[ReadOnly] = False
txt3A.Value = "SNMP Operation"
dataGridRow.Cells.Add(txt3A)
txt3A.[ReadOnly] = True
dataGridRow.Cells.Add(cbo2)
dataGridRow.Height = 20
DataGridView1.Rows.Add(dataGridRow)
dataGridRow = New DataGridViewRow()
cells = New DataGridViewCell(1) {}
Dim txt4A As New DataGridViewTextBoxCell()
Dim txt4B As New DataGridViewTextBoxCell()
txt4A.Value = "Community String"
txt4B.Value = "public"
dataGridRow.Cells.Add(txt4A)
dataGridRow.Cells.Add(txt4B)
dataGridRow.Height = 20
DataGridView1.Rows.Add(dataGridRow)
End Sub
Private Sub dataGridView1_EditingControlShowing(ByVal sender As Object, ByVal e As DataGridViewEditingControlShowingEventArgs)
Dim comboControl As DataGridViewComboBoxEditingControl = TryCast(e.Control, DataGridViewComboBoxEditingControl)
If comboControl IsNot Nothing Then
' Set the DropDown style to get an editable ComboBox
If comboControl.DropDownStyle <> ComboBoxStyle.DropDown Then
comboControl.DropDownStyle = ComboBoxStyle.DropDown
End If
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim result As Dictionary(Of Oid, AsnType)
Dim cbo1 As New DataGridViewComboBoxCell()
Dim txt1B As New DataGridViewTextBoxCell()
txt1B.Value = "203.81.211.117"
Dim host As String
Dim community As String
host = DataGridView1.Rows(0).Cells(1).Value.ToString
community = DataGridView1.Rows(3).Cells(1).Value.ToString
Dim txt4B As New DataGridViewTextBoxCell()
txt4B.Value = "public"
Dim snmp As New SimpleSnmp
snmp = New SimpleSnmp(DataGridView1.Rows(0).Cells(1).Value.ToString, DataGridView1.Rows(3).Cells(1).Value.ToString)
'abc.Text = txtsnmpaction.SelectedItem
result = snmp.Get(SnmpVersion.Ver1, New String() {DataGridView1.Rows(1).Cells(1).Value.ToString()})
'result = snmp.GetNext(SnmpVersion.Ver1, requestoid)
'If (txtsnmpaction = "GetBulk")
'result = snmp.GetBulk(New String() {".1.3.6.1.2", ".1.3.6.1.3"})
' End If
If Not snmp.Valid Then
MessageBox.Show("Invalid hostname/community")
End If
If result IsNot Nothing Then
Dim kvp As KeyValuePair(Of Oid, AsnType)
For Each kvp In result
MessageBox.Show(kvp.Key.ToString)
MessageBox.Show(SnmpConstants.GetTypeName(kvp.Value.Type))
MessageBox.Show(kvp.Value.ToString())
Next kvp
Else
MessageBox.Show("No results received")
End If
End Sub
结束班
答案 0 :(得分:0)
我将SNMP操作设置为只读文本字段并以编程方式设置它。处理DataGridView1.CellValueChanged事件。
编辑:更改说明而不是SNMP操作。
Private Sub DataGridView1_CellValueChanged(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged
If e.ColumnIndex = 3 Then
Dim Row As DataGridViewRow = DataGridView1.Rows(e.RowIndex)
Dim Description As String = Nothing
Select Case Row.Cells(3).Value
Case "1.3.6.1.2.1.1.1.0" : Description = "sysDescr"
...
End Select
Row.Cells(5).Value = Description ' Change (5) to description column index.
End If
End Sub