This sample logs the events of a DropDown and a DropDownList combo box. While the check box is set, its DropDownOpening event handler cancels the dropdowns.
The source code is located at C:\Program Files (x86)\Softelvdm\SftBox NET 3.0\Samples\VB\EventViewer\Form1.vb.
Imports System.ComponentModel
Imports System.Reflection
Imports Softelvdm.SftBoxNET
Public Class Form1
Private strLastEvent As String = ""
Private fLastEventDup As Boolean = False
' This is a small helper routine to show all properties and fields of an object
Private Sub DumpValues(ByVal title As String, ByVal o As Object)
Dim s As String = ""
If strLastEvent = title Then
If Not fLastEventDup Then
s = "Additional " + title + " events ... now suppressed"
fLastEventDup = True
Else
Return
End If
Else
strLastEvent = title
fLastEventDup = False
Dim api() As PropertyInfo = o.GetType().GetProperties()
For Each pi As PropertyInfo In api
s += pi.Name + "=" + Describe(pi.GetValue(o, New Object() {})) + " "
Next
Dim afi() As FieldInfo = o.GetType().GetFields()
For Each fi As FieldInfo In afi
s += fi.Name + "=" + Describe(fi.GetValue(o)) + " "
Next
End If
Dim item As ListViewItem = ListView1.Items.Add(New ListViewItem(New String() {title, s}))
ListView1.SelectedItems.Clear()
item.Selected = True
item.EnsureVisible()
End Sub
Private Function Describe(ByVal value As Object) As String
If value Is Nothing Then
Return "Nothing"
End If
Return value.ToString()
End Function
Private Sub ButtonClear_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ButtonClear.Click
ListView1.Items.Clear()
strLastEvent = ""
fLastEventDup = False
End Sub
' The text of the selected item, as the combo box shows it
Private Function Selection(ByVal box As SftBox) As String
If box.SelectedItem Is Nothing Then
Return "none"
End If
Return box.DisplayText(box.SelectedItem)
End Function
' SftBox1 - an edit field with a dropdown; typing completes the name of a fruit
Private Sub SftBox1_SelectedItemChanged(ByVal sender As Object, ByVal e As EventArgs) Handles SftBox1.SelectedItemChanged
DumpValues("SftBox1.SelectedItemChanged (" + Selection(SftBox1) + ")", e)
End Sub
Private Sub SftBox1_SelectionCommitted(ByVal sender As Object, ByVal e As EventArgs) Handles SftBox1.SelectionCommitted
DumpValues("SftBox1.SelectionCommitted (" + Selection(SftBox1) + ")", e)
End Sub
Private Sub SftBox1_SelectedValueChanged(ByVal sender As Object, ByVal e As EventArgs) Handles SftBox1.SelectedValueChanged
DumpValues("SftBox1.SelectedValueChanged", e)
End Sub
Private Sub SftBox1_EditTextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles SftBox1.EditTextChanged
DumpValues("SftBox1.EditTextChanged (" + SftBox1.Text + ")", e)
End Sub
Private Sub SftBox1_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles SftBox1.TextChanged
DumpValues("SftBox1.TextChanged (" + SftBox1.Text + ")", e)
End Sub
Private Sub SftBox1_DropDownOpening(ByVal sender As Object, ByVal e As CancelEventArgs) Handles SftBox1.DropDownOpening
e.Cancel = CheckBlock.Checked
DumpValues("SftBox1.DropDownOpening" + If(e.Cancel, " (canceled)", ""), e)
End Sub
Private Sub SftBox1_DropDownOpened(ByVal sender As Object, ByVal e As EventArgs) Handles SftBox1.DropDownOpened
DumpValues("SftBox1.DropDownOpened", e)
End Sub
Private Sub SftBox1_DropDownClosed(ByVal sender As Object, ByVal e As DropDownClosedEventArgs) Handles SftBox1.DropDownClosed
DumpValues("SftBox1.DropDownClosed", e)
End Sub
Private Sub SftBox1_DropDownResized(ByVal sender As Object, ByVal e As EventArgs) Handles SftBox1.DropDownResized
DumpValues("SftBox1.DropDownResized (" & SftBox1.DropDownSize.Width & " x " & SftBox1.DropDownSize.Height & ")", e)
End Sub
Private Sub SftBox1_Enter(ByVal sender As Object, ByVal e As EventArgs) Handles SftBox1.Enter
DumpValues("SftBox1.Enter", e)
End Sub
Private Sub SftBox1_Leave(ByVal sender As Object, ByVal e As EventArgs) Handles SftBox1.Leave
DumpValues("SftBox1.Leave", e)
End Sub
Private Sub SftBox1_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) Handles SftBox1.KeyDown
DumpValues("SftBox1.KeyDown", e)
End Sub
' SftBox2 - a list of countries with two columns, without an edit field
Private Sub SftBox2_SelectedItemChanged(ByVal sender As Object, ByVal e As EventArgs) Handles SftBox2.SelectedItemChanged
DumpValues("SftBox2.SelectedItemChanged (" + Selection(SftBox2) + ")", e)
End Sub
Private Sub SftBox2_SelectionCommitted(ByVal sender As Object, ByVal e As EventArgs) Handles SftBox2.SelectionCommitted
DumpValues("SftBox2.SelectionCommitted (" + Selection(SftBox2) + ")", e)
End Sub
Private Sub SftBox2_SelectedValueChanged(ByVal sender As Object, ByVal e As EventArgs) Handles SftBox2.SelectedValueChanged
DumpValues("SftBox2.SelectedValueChanged", e)
End Sub
Private Sub SftBox2_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles SftBox2.TextChanged
DumpValues("SftBox2.TextChanged (" + SftBox2.Text + ")", e)
End Sub
Private Sub SftBox2_DropDownOpening(ByVal sender As Object, ByVal e As CancelEventArgs) Handles SftBox2.DropDownOpening
e.Cancel = CheckBlock.Checked
DumpValues("SftBox2.DropDownOpening" + If(e.Cancel, " (canceled)", ""), e)
End Sub
Private Sub SftBox2_DropDownOpened(ByVal sender As Object, ByVal e As EventArgs) Handles SftBox2.DropDownOpened
DumpValues("SftBox2.DropDownOpened", e)
End Sub
Private Sub SftBox2_DropDownClosed(ByVal sender As Object, ByVal e As DropDownClosedEventArgs) Handles SftBox2.DropDownClosed
DumpValues("SftBox2.DropDownClosed", e)
End Sub
Private Sub SftBox2_Enter(ByVal sender As Object, ByVal e As EventArgs) Handles SftBox2.Enter
DumpValues("SftBox2.Enter", e)
End Sub
Private Sub SftBox2_Leave(ByVal sender As Object, ByVal e As EventArgs) Handles SftBox2.Leave
DumpValues("SftBox2.Leave", e)
End Sub
Private Sub SftBox2_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) Handles SftBox2.KeyDown
DumpValues("SftBox2.KeyDown", e)
End Sub
End Class