Imports System.Reflection
Imports Softelvdm.Controls
Imports Softelvdm.SftTreeNET

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    sftTree1.Initializing = True
    sftTree1.Columns.Count = 1
    ' This sample demonstrates how radiobuttons are used in cells.
    ' To prepare for this sample, create a new project with a blank form and add
    ' a SftTree/NET control named sftTree1.
    ' In addition, adjust the following FromFile method to use a (small) bitmap
    ' that is located on your system.
    Dim img As Image = Bitmap.FromFile("..\\..\\test.gif")

    ' Add an item
    Dim item As ItemClass = sftTree1.ItemCollection.Add()
    Dim cell As CellClass = item.Cells(0)
    item.Image = img
    cell.Text = "Category 1"
    ' Add some sub items
    Dim subItem As ItemClass = item.Add()
    Dim rb As RadioButtonPartClass = New RadioButtonPartClass(RadioButtonStateEnum.Checked)
    subItem.Cells(0).Parts.Add(rb)
    subItem.Cells(0).Parts.Add(New CheckBoxPartClass())
    subItem.Cells(0).Parts.Add(New TextPartClass("Item 1"))
    subItem = item.Add()
    rb = New RadioButtonPartClass(RadioButtonStateEnum.Unchecked)
    subItem.Cells(0).Parts.Add(rb)
    subItem.Cells(0).Parts.Add(New TextPartClass("Item 2"))
    subItem = item.Add()
    rb = New RadioButtonPartClass(RadioButtonStateEnum.Unchecked)
    subItem.Cells(0).Parts.Add(rb)
    subItem.Cells(0).Parts.Add(New TextPartClass("Item 3"))

    sftTree1.Columns.MakeOptimal(0, False)
    sftTree1.RecalcHorizontalExtent()
    sftTree1.Initializing = False
End Sub

' ItemClick event
Private Sub sftTree1_ItemClick(ByVal sender As Object, ByVal e As Softelvdm.SftTreeNET.ItemClickEventArgs) Handles sftTree1.ItemClick
    Debug.Write("** ItemClick")
    DumpValues(e)
End Sub

' This is a small helper routine to show all properties and fields of an object
Private Sub DumpValues(ByVal o As Object)
    Dim api() As PropertyInfo = o.GetType().GetProperties()
    For Each pi As PropertyInfo In api
        Debug.Write(" " & pi.Name & " " & pi.GetValue(o, New Object() {}))
    Next
    Dim afi() As FieldInfo = o.GetType().GetFields()
    For Each fi As FieldInfo In afi
        Dim t As Object = fi.GetValue(o)
        Dim s As String = "(null)"
        If Not t Is Nothing Then s = t.ToString()
        Debug.Write(" " & fi.Name & " " & s)
    Next
    Debug.WriteLine("")
End Sub
End Class