### Customized ListView with CheckBox TextField ComboBox

As an example a customized ListView is created with a checkbox, textfield and combobox.
This type of customized ListView could be used to manage settings.
The basic principle is to add to the ListView controls and assign an unique tag per control.
This unique tag is being used to get or set values in the control assigned.
Note:
Instead of the Tag value, another option is to use the ID value.
The ID could be given a more tangible name, which might be easier to work with.
Define Global Var
`Sub Process_Globals
...
Dim listviewTools As ListView
...
Create the customized ListView
' Create a customized listview with a checkbox, textfield and combobox
`Sub initListViewTools
tabpaneMain.Visible = False
' Init the listview and provide eventname
listviewTools.Initialize("listviewTools")
' Add the listview to the mainform, with some sizes
MainForm.RootPane.addNode(listviewTools , 10, 10, 400, 500)
' Add some controls
' New checkbox - Init with eventname - this is used to action checkbox event according to the checkbox property
' The Tag value is key to determine the control and its value. The tag must be unique per control
Dim cb As CheckBox
cb.Initialize("listviewToolsCheckBox")
cb.Id = "listviewToolsCheckBox"
cb.Tag = 1
cb.Text = "CheckBox 1"
cb.Style = "-fx-text-fill: Blue; -fx-font-size: 1.1em; "
listviewTools.Items.Add(cb)
'
Dim tf As TextField
tf.Initialize("listviewToolsTextField")
tf.Id = "listviewToolsTextField"
tf.Tag = 2
tf.Text = "TextField 1"
tf.Style = "-fx-text-fill: Blue; -fx-font-size: 1.1em; "
listviewTools.Items.Add(tf)
'
Dim combo As ComboBox
combo.Initialize("listviewToolsComboBox")
combo.Id = "listviewToolsComboBox"
combo.Tag = 3
combo.Items.AddAll(Array As String("Value 1", "Value 2", "Value 3"))
combo.Editable = False
combo.SelectedIndex = 0
listviewTools.Items.Add(combo)
End Sub`
Get the values from the Controls in the ListView
`Sub getListViewToolsValues
Log("*** Get ListViewTools Values ***")
For i = 0 To listviewTools.Items.Size - 1
' Get the object from the listview and assign as a control (because not known what control type it is)
Dim c As Control = listviewTools.Items.Get(i)
Log(c.Id)
' Based upon the assigned Tag value, the control is defined and value obtained accordingly
If c.Tag = 1 Then
Dim cb As CheckBox
cb = c
Log("listviewTools CheckBox Action = Tag:" & cb.Tag & " = Checked:" & cb.checked)
End If
If c.Tag = 2 Then
Dim tf As TextField
tf = c
Log("listviewTools TextField Action = Tag:" & tf.Tag & " = Text:" & tf.Text)
End If
If c.Tag = 3 Then
Dim combo As ComboBox
combo = c
Log("listviewTools ComboBox Action = Tag:" & combo.Tag & " = Index:" & combo.SelectedIndex & " / " & combo.Items.Get(combo.SelectedIndex))
End If
Next
End Sub`
Set the values = using dummy values
`Sub setListViewToolsValues
Log("*** Get ListViewTools Values ***")
For i = 0 To listviewTools.Items.Size - 1
' Get the object from the listview and assign as a control (because not known what control type it is)
Dim c As Control = listviewTools.Items.Get(i)
' Based upon the assigned Tag value, the control is defined and value obtained accordingly
If c.Tag = 1 Then
Dim cb As CheckBox
cb = c
If cb.Checked Then cb.Checked = False Else cb.Checked = True
Log("listviewTools CheckBox Action = Tag:" & cb.Tag & " = Checked:" & cb.checked)
End If
If c.Tag = 2 Then
Dim tf As TextField
tf = c
tf.Text = DateTime.Date(DateTime.now) & " " & DateTime.Time(DateTime.now)
Log("listviewTools TextField Action = Tag:" & tf.Tag & " = Text:" & tf.Text)
End If
If c.Tag = 3 Then
Dim combo As ComboBox
combo = c
combo.SelectedIndex = 0
Log("listviewTools ComboBox Action = Tag:" & combo.Tag & " = Index:" & combo.SelectedIndex & " / " & combo.Items.Get(combo.SelectedIndex))
End If
Next
End Sub`
Set a new value for a specific control in the customized listview
' Set the a new value for a control in the customized listview values.
' The Tag value is used to determine which control
' Examples:
' setListViewToolsValue(1, True)
' setListViewToolsValue(2, "Moin Moin")
' setListViewToolsValue(3, 1)
' Notes:
' Add more checks to the values provided else runtime error
'
`Sub setListViewToolsValue(tag As Int, newvalue As String)
Log("*** Get ListViewTools Values ***")
' Loop thru the listview items = Controls
For i = 0 To listviewTools.Items.Size - 1
' Get the object from the listview and assign as a control (because not known what control type it is)
Dim c As Control = listviewTools.Items.Get(i)
' If tag found then determine which control and assign the new value
If c.tag = tag Then
' Based upon the assigned Tag value, the control is defined and value obtained accordingly
If c.tag = 1 Then
Dim cb As CheckBox
cb = c
cb.Checked = newvalue
Log("listviewTools CheckBox Action = Tag:" & cb.tag & " = Checked:" & cb.checked)
Return
End If
If c.tag = 2 Then
Dim tf As TextField
tf = c
tf.Text = newvalue
Log("listviewTools TextField Action = Tag:" & tf.tag & " = Text:" & tf.Text)
Return
End If
If c.tag = 3 Then
Dim combo As ComboBox
combo = c
combo.SelectedIndex = newvalue
Log("listviewTools ComboBox Action = Tag:" & combo.tag & " = Index:" & combo.SelectedIndex & " / " & combo.Items.Get(combo.SelectedIndex))
Return
End If
End If
Next
End Sub`
`

Changed: , Category: ListView, File: T6C216M1583.htm, ID: 1583